I use retrofit2 in my project and I need to parse some json answer into custom object. So I created deserializer and called it in GsonBuilder
private final Gson _gson = new GsonBuilder()
.registerTypeAdapter(DaysList.class, new DaysDeserializer())
.create();
After that I defined Retrofit
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(_activity.getString(R.string.config_api_url))
.addConverterFactory(GsonConverterFactory.create(_gson))
.build();
But with defined retrofit service
Call<DaysList> retrofitHolidaysRequest()
I got an exception. After that I changed method signature to service method and it became:
DaysList retrofitHolidaysRequest()
Also I added to Retrofit.Builder my own CallAdapter.Factory and everything have worked as I need:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(_activity.getString(R.string.config_api_url))
.addConverterFactory(GsonConverterFactory.create(_gson))
.addCallAdapterFactory(new ResponseCallAdapterFactory())
.build();
So the question is: Is it possible create own deserializers without defining own CallAdapters? If it is possible then what I did wrong?