I am trying to deserialise the following JSON using Jackson library. This JSON is very similar which mentioned in this question. My question is: How to deserialise following JSON?
{
"A": [
{
"id": 16,
"logo": "QJQSZzbXurElfHYcq6hcbPuaWKVfQU31lx2eSIIr.png",
},
{
"id": 20,
"logo": "AizaZzbXurElfHYcq6PuaWKV2761lx2eSLESASFr.png",
}
],
"B": [
{
"id": 42,
"logo": "tBYhHGTNTCYT60RZJydMyGgg47Tla36ISuRj4p0e.png",
},
{
"id": 44,
"logo": "kCZveUWo9eqIZc25deE4ln8llxlbBviRolk4PsCm.png",
}
]
}
Here is MonthTree
class:
public class MonthTree {
private int id;
private String logo;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
}
However, I tried to get list/array of array names (the A
and B
), id
and logo
properties, but I failed with it. Here is what I tried to do at all:
ObjectMapper mapper = new ObjectMapper();
List<MonthTree> monthTrees = mapper.readValue(json_res, new TypeReference<List<MonthTree>>(){});
So, I got the following exception:
Cannot deserialize instance of
com.talmir.myApp.utils.MonthTree[]
out of START_OBJECT token
p.s. I am new with this library, so don't know what else functionalities this library has.