Retrofit JSON Response:
{ "data": [{ "id": 1224410, "amount": "900200.00", "meta": { "referenceId": "referenceId","time": "2017-11-01T15:42:26Z","type": "send" } }], "version": "v2" } These are model structures:
public class MyOject { @SerializedName("id") private int mId; @SerializedName("amount") private double mAmount; @SerializedName("meta") private JSONObject mMeta; } I always get null in the mMeta variable
Update code class Wrapper using to parse response from JSONObject:
public class ResponseWrapper<DataType> { @SerializedName("data") private DataType mData; @SerializedName("version") private String mVersion; } This is Callback. I use it to specify the type of data to receive.
public class CallbackWithData<T> implements Callback<ResponseWrapper<T>> { @Override public final void success(ResponseWrapper<T> data, Response response) { this.success(data.getData(), data.getVersion()); } public abstract void success(T data, String version); } This is the API I use, which defines the desired object.
@GET("/transaction") void listTransactions(@Header(Constants.Header.LOGIN_SECRET) String loginSecret, CallbackWithData<List<MyObject>> callback);
Retrofitand defaultGsonConverterto parsing response.RestAdapter.Builder restBuilder = new RestAdapter.Builder() .setClient(new OkClient(new OkHttpClient())) .setConverter(new GsonConverter(gson))and auto parsing toMyObjectThe values I have declared through the annotation