Ich habe diesen Aufruf in async Aufgabe. Alle Parameter sind korrekt. Im Postman- oder Advance Rest-Client funktioniert der Aufruf einwandfrei und es wird ein json mit einer Liste von Objekten zurückgegeben. Aber wenn ich versuche, mit Feder diesen Anruf in Android zu tun, habe ich diesen Fehler:JsonMappingException auf android Frühling httprequest
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token at [Source: [email protected]; 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: [email protected]; line: 1, column: 1]
Dies ist die erwartete json Antwort
[
{
"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"
}]
dies mein AsyncTask ist
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();
Kann jemand Hilf mir bitte?