Pojo pojo;
json = {
"response" : [
{
"id" : "1a",
"name" : "foo"
},
{
"id" : "1b",
"name" : "bar"
}
]
}
ObjectMapper mapper = new ObjectMapper();
JsonNode root = objectMapper.readTree(json);
pojo = objectMapper.readValue(root.path("response").toString(),new TypeReference<List<Pojo>>() {});
JSON JSON. JSON. , JSON,
root.path("response")
However, this will return a JSON tree. To make a string, I used the toString method. Now you have a line as shown below "[{" id ":" 1a "," name ":" fu "}, {" id ":" 1b "," name ":" bar "}]" You can map this string to a JSON array as follows
String desiredString = root.path("response").toString();
pojos = objectMapper.readValue(desiredString ,new TypeReference<List<Pojo>>() {});
source
share