Android Gson Using Gson as serializer with Retrofit

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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.



Got any Android Question?