I'm extending the default Retrofit 2 Callback:
abstract class APICallback<T> implements Callback<T> {
@Override
public void onResponse(Call<T> call, Response<T> response) {
if (!response.isSuccessful()) {
// Cast response.body() to my POJO class, results in null
MyClass myClass = (MyClass) response.body();
}
}
@Override
public void onFailure(Call<T> call, Throwable t) {
// TODO ...
}
}
How can I downcast the generic type of the Response to my own class? Should this process be automatic? I'm using GsonConverter for the client.