I have this call in async task. All parameters are correct. In postman or advance rest client the call work fine and It return a json with a list of objects. But if I try to do this call in android with spring I have this error:
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token at [Source: org.apache.http.conn.EofSensorInputStream@1961b5e; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token at [Source: org.apache.http.conn.EofSensorInputStream@1961b5e; line: 1, column: 1]
This is the expected json response
[
{
"id": 57,
"user_id": 2,
"category_id": 5,
"notification_title": "test 9",
"notification_body": "breve 9",
"description": "Sd sdfds sdfs dfsd fdsf",
"image": null,
"code": "2-5942525969dfa",
"start_date": null,
"expiration_date": null,
"created_at": "2017-06-15 09:24:41",
"updated_at": "2017-06-15 09:24:41"
},
{
"id": 56,
"user_id": 2,
"category_id": 4,
"notification_title": "test 8",
"notification_body": "breve desc 8",
"description": "Sdfsdf sdfds dsfs dsfds",
"image": null,
"code": "2-59424e24570a2",
"start_date": null,
"expiration_date": null,
"created_at": "2017-06-15 09:06:44",
"updated_at": "2017-06-15 09:06:44"
}]
this is my AsyncTask
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
JSONObject body = new JSONObject();
try {
body.put("api_token", Config.API_TOKEN);
body.put("user_id", Config.USER_ID);
} catch (JSONException e) {
e.printStackTrace();
}
try {
return template.postForObject(
Config.SERVICE_URL_BASE + "/getallposts",
body.toString(),
String.class
);
} catch (Exception e) {
listener.onError(e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(String response) {
if (response != null) {
try {
List<JSONObject> jsonObjects = ResponseConverter.toJSONArray(response);
listener.onSuccess(jsonObjects);
} catch (JSONException e) {
listener.onError(context.getResources().getString(R.string.cannot_load_posts));
}
} else {
listener.onError(context.getResources().getString(R.string.cannot_load_posts));
}
}
}.execute();
Can someone help me please?