I\'m using retrofit 2 along with rx java
Situation: the app sends some request, then i get the response in json-format that is automatically converted to User dto,
I believe in the case you mentioned you will just enter into your onError
handling, because retrofit will fail to deserialize your response, as it's not formatted as a List
. You could potentially handle your case through that based off of the exception type.
If you can't alter the api to return consistent response types, you will have to look into using TypedInput, and possibly a converter.
Additionally, while it may not be completely relevant/overkill to the situation at hand, TypeAdapters bear mentioning. They'll let you determine how retrofit
deserializes gson
on a per class basis.
Gson gson = new GsonBuilder()
.registerTypeAdapter(MyClass.class, new MyAdapter())
.create();
RestAdapter adapter = new RestAdapter.Builder()
.setConverter(new GsonConverter(gson))
.build();