Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JacksonConverterFactory in Retrofit.Builder()

When using Gson for the Retrofit Builder I use:

 Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(CustomAPI.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

How to add a JacksonConverterFactory to a Retrofit Builder?

Using

compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-jackson:1.9.0'

as Gradle Dependencies

On the internet I can get the class for the factory, but this must be imported somehow, as in all the tutorials they use Gson. The reason I need Jackson is because the models provided by the company make use of Jackson formatters.

like image 222
Rafael Avatar asked Oct 05 '16 12:10

Rafael


1 Answers

It's possible to achieve that using this code snippet

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(WeCityAPI.BASE_URL)
            .addConverterFactory(JacksonConverterFactory.create())
            .build();

and retrofit2 as dependency?

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
like image 175
ruX Avatar answered Oct 18 '22 12:10

ruX