Search code examples
javaandroidconvertersretrofitjson-api

Retrofit JSONAPI converter needed?


Is there some way to use the JSONAPI spec with Retrofit?, don't know how this will work or how to start, any help?.

I found this gist: https://gist.github.com/Gregadeaux/cbcc3781fda9d7fa6498, it uses RxJava and some other libraries.

Also, is a converter needed?.

Thank you.


Solution

  • https://github.com/jasminb/jsonapi-converter is what you're looking for

    from the docs

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