Using Gson as serializer with Retrofit

suggest change

First of all you need to add the GsonConverterFactory to your build.gradle file

compile 'com.squareup.retrofit2:converter-gson:2.1.0'

Then, you have to add the converter factory when creating the Retrofit Service:

Gson gson = new GsonBuilder().create();
new Retrofit.Builder()
        .baseUrl(someUrl)
        .addConverterFactory(GsonConverterFactory.create(gson))
        .build()
        .create(RetrofitService.class);

You can add custom converters when creating the Gson object that you are passing to the factory. Allowing you to create custom type conversions.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents