Retrofit multiple response types
问题 How can I use Retrofit2 to parse these two kinds of API responses? Ok response (HTTP 200): { "data": { "foo": "bar" } } Error response (HTTP 200): { "error": { "foo": "bar" } } I've read tons of SO questions and tutorials, but I don't know how to do that, I've tried: GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapterFactory(new ItemTypeAdapterFactory()); Gson gson = gsonBuilder.create(); final Retrofit retrofit = new Retrofit.Builder() .client(getOkHttpClient())