I use an API that always returns a JSON object that looks like this:
public class ApiResponse<T> { public boolean success; public T data; }
Field
data strong> is a JSON object that contains all the valuable information. Of course, these are different for different requests. Therefore, my modified interface looks like this:
@GET(...) Observable<ApiResponse<User>> getUser();
And when I want to process the answer, I need to do, for example:
response.getData().getUserId();
I really don't need this boolean success field, and I would like to omit it, so my interface for modification might look like this:
@GET(...) Observable<User> getUser();
Is it possible to do this in Gson? Or maybe a neat Rx function that automatically converts this?
EDIT: json example:
{ "success": true, "data": { "id": 22, "firstname": "Jon", "lastname": "Snow" } }
EDIT 2: I was able to do this using cross-conversion, where I manually modify the response body. It works, but if you have other suggestions, please write them :)
json android gson retrofit rx-java
rafakob Dec 15 '15 at 12:07 2015-12-15 12:07
source share