given JSON
{"news" : [ {...}, {...}, {...} ] }
the array contains custom objects, which I already declared as POJOs. Want I simply want to map my custom objects by keypath “news”.
restTemplate.exchange(URI + "/news/{limit}/", HttpMethod.GET, CustomObject[].class, 10)
throws an exception, because this JSON is expected
[ {...}, {...}, {...}]
Is there a way to configure RestTemplate to match my needs?
Regards
Update:
restTemplate.exchange(URI + "/news/{limit}/", HttpMethod.GET, requestEntity, JsonElement.class,10).getBody().getAsJsonObject().get("news");
CustomObject[] result = gson.fromJson(body, CustomObject[].class);
This snippet works but is there a cleaner way? For my suprise mapping to JSONObject doesn’t even worked, JSONElement did the job at the end.
Well I’ll add my update in here to close this question. If someone can provide a cleaner solution I’ll be happy to accept it:
This snippet works but is there a cleaner way? For my suprise mapping to JSONObject doesn’t even worked, JSONElement did the job at the end.