Hi I am trying to get data from the API and I am getting the next error:
Expected BEGIN_ARRAY but was BEGIN_OBJECT
The data that I am getting is the following:
"code": "01",
"data": {
"code": "0",
"time": "14-05-2019 16:22:28.661",
"data": [
{
"geometry": {
"BoundingBox": null,
"ExtraMembers": null,
"Type": 7,
"Coordinates": {
"Latitude": 40.401609,
"Values": [
-3.674735,
40.401609
],
"Longitude": -3.674735
},
"CoordinateReferenceSystem": null
}
},
{
"geometry": {
"BoundingBox": null,
....
And the pojo for get this data is the next:
public class ApiResponse<T extends ApiResponseData> {
...
@SerializedName("data")
@Expose
private List<T> data;
...
}
public class DData implements ApiResponseData {
...
And the retrofit call for get data is the next:
public void getListOfDs(final MutableLiveData<ApiResponse<DData>> data) {
Call<ApiResponse<DData>> call = CApiInterface.getListOfDs(ID_CLIENT);
call.enqueue(new Callback<ApiResponse<DData>>() {
@Override
public void onResponse(Call<ApiResponse<DData>> call, Response<ApiResponse<DData>> response) {
ApiResponse<DData> apiResponse = response.body();
data.setValue(apiResponse);
}
@Override
public void onFailure(Call<ApiResponse<DData>> call, Throwable t) {
data.setValue(createFailedResponse());
call.cancel();
}
});
}
The question is why am I getting this error, in the ApiResponse
I have a List in this case List and I am getting a list of DData
, for another case like the response is only a single DData
this work perfectly any idea?
Any idea that how can solve it?
Thanks.