【问题标题】:Retrofit JSONAPI converter needed?需要改造 JSONAPI 转换器吗?
【发布时间】:2015-12-11 21:39:56
【问题描述】:

有什么方法可以将 JSONAPI 规范与 Retrofit 一起使用吗?不知道这将如何工作或如何开始,有什么帮助吗?。

我找到了这个要点:https://gist.github.com/Gregadeaux/cbcc3781fda9d7fa6498,它使用了 RxJava 和其他一些库。

另外,需要转换器吗?

谢谢。

【问题讨论】:

    标签: java android converter retrofit json-api


    【解决方案1】:

    改造提供list现有的JSON转换器,你也可以实现Converter.Factory接口并提供你自己的转换器。然后,您可以在构建适配器时在实例中传递您的类。

    相关资源

    1. Retrofit — Define a Custom Response Converter

    【讨论】:

      【解决方案2】:

      https://github.com/jasminb/jsonapi-converter 就是你要找的东西

      来自文档

      // Create object mapper
      ObjectMapper objectMapper = new ObjectMapper();
      
      // Set serialisation/deserialisation options if needed (property naming strategy, etc...)
      
      Retrofit retrofit = new Retrofit.Builder()
              .baseUrl("https://yourapi")
              .addConverterFactory(new JSONAPIConverterFactory(objectMapper, Book.class, Author.class))
              .build();
      
      // Create service using service interface
      MyBooksService booksService = retrofit.create(MyBooksService.class);
      

      【讨论】:

        猜你喜欢
        • 2014-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-04
        • 2013-10-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多