【发布时间】:2015-12-11 21:39:56
【问题描述】:
有什么方法可以将 JSONAPI 规范与 Retrofit 一起使用吗?不知道这将如何工作或如何开始,有什么帮助吗?。
我找到了这个要点:https://gist.github.com/Gregadeaux/cbcc3781fda9d7fa6498,它使用了 RxJava 和其他一些库。
另外,需要转换器吗?
谢谢。
【问题讨论】:
标签: java android converter retrofit json-api
有什么方法可以将 JSONAPI 规范与 Retrofit 一起使用吗?不知道这将如何工作或如何开始,有什么帮助吗?。
我找到了这个要点:https://gist.github.com/Gregadeaux/cbcc3781fda9d7fa6498,它使用了 RxJava 和其他一些库。
另外,需要转换器吗?
谢谢。
【问题讨论】:
标签: java android converter retrofit json-api
改造提供list现有的JSON转换器,你也可以实现Converter.Factory接口并提供你自己的转换器。然后,您可以在构建适配器时在实例中传递您的类。
相关资源:
【讨论】:
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);
【讨论】: