6

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

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

另外,需要转换器吗?

谢谢你。

4

2 回答 2

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);
于 2017-11-20T04:21:54.473 回答
0

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

相关资源

  1. Retrofit - 定义自定义响应转换器
于 2015-09-15T15:15:47.327 回答