需要改造 JSONAPI 转换器吗?

Retrofit JSONAPI converter needed?

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

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

另外,需要转换器吗?

谢谢。

retrofit 提供 list of existed JSON converters, also you can implements Converter.Factory 接口并提供您自己的转换器。然后,您可以在构建适配器时在实例中传递 class。

相关资源:

  1. Retrofit — Define a Custom Response Converter

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);