I would like to parse a response from the NYT Search API given in JSON format. The JSON string looks as follows (excerpt):
{"facets" :
{"des_facet" :
[
{"count" : 745 , "term" : "POLITICS AND GOVERNMENT"} ,
{"count" : 702 , "term" : "UNITED STATES INTERNATIONAL RELATIONS"}
],
"desk_facet" :
[
{"count" : 2251 , "term" : "Foreign Desk"} ,
{"count" : 242 , "term" : "Editorial Desk"}
]
}
}
On Java side, i prepared the following object hierarchy:
public class Container {
Facet facets;
}
public class Facet {
Collection<Elements> des_facet;
Collection<Elements> desk_facet;
}
public class Elements {
private int count;
private String term;
}
… which is obviously not working. I am new to JSON. Therefore, the nested structure of elements is confusing.
Thanks for your help!
The defined class structure matches the example JSON perfectly well, and deserializes without error for me.