I'm using an API which always returns JSON object that looks like this:
public class ApiResponse<T> {
public boolean success;
public T data;
}
data field is a JSON object that holds all valuable information. Of course it's different for different requests. So my retrofit interface looks like this:
@GET(...)
Observable<ApiResponse<User>> getUser();
And when I want to handle response I need to do eg.:
response.getData().getUserId();
I don't really need that boolean success field and I'd like to omit it, so that my retrofit interface could look like this:
@GET(...)
Observable<User> getUser();
Is it possible to do that in Gson? Or maybe a neat Rx function which will automatically transform this?
EDIT: Example json:
{
"success": true,
"data": {
"id": 22,
"firstname": "Jon",
"lastname": "Snow"
}
}
EDIT 2: I've manged to do this with retrofit interceptor where I manually modify response body. It works but if you got any other suggestions, please post them :)