I am trying to use AutoValue library from here
I have using Retrofit 2.0 for web service call, all web service request getting failed with HTTP Request error 400. By further investigation I got to know that I have to set the TypeAdapterFactory
and pass it to Retrofit Builder like
Retrofit retrofit = new Retrofit
.Builder()
.addConverterFactory(gsonConverterFactory)
.baseUrl("http://url.com/")
.build()
This answer is available at How to use AutoValue with Retrofit 2?
But the gsonConverterFactory
being used there is like
public class AutoValueGsonTypeAdapterFactory implements TypeAdapterFactory {
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Class<? super T> rawType = type.getRawType();
if (rawType.equals(SignIn.class)) {
return (TypeAdapter<T>) SignIn.typeAdapter(gson);
}
return null;
}
}
where rawType.equals(SignIn.class)
is being used, so my question is, is there any way to make generic version of AutoValueGsonTypeAdapterFactory
or I have to create separate AutoValueGsonTypeAdapterFactory
for each web service request with respective DTO??
Thanks in advance