给定以下json:
{ "response": {
"totalProcessingTime": "271.0",
"resultSets": {
"products": {
"firstHit": "1",
"lastHit": "10",
"totalHits": "77",
"hits": [
{
"number": "1",
"dmsubcategory": "TV, lyd og bilde",
"collection": "tilbud",
"title": "<b>TV</b> Panasonic 47 TX-LU 7ET5Y"
},
{
"number": "2",
"dmsubcategory": "TV, lyd og bilde",
"collection": "tilbud",
"title": "<b>TV</b> Panasonic 47 TX-LU 7ET5Y"
},
{
"number": "3",
"dmsubcategory": "TV, lyd og bilde",
"collection": "tilbud",
"title": "<b>TV</b> Panasonic 47 TX-LU 7ET5Y"
}
]
}
}
}
}
我正在使用以下代码调用杰克逊:
ObjectMapper mapper = new ObjectMapper();
SearchResult searchResult = mapper.readValue(new URL(jsonUrl + queryUrl), SearchResult.class);
我已经为产品类看起来像的整个层次结构收集了 POJO:
public class Products {
public List<Hits> hits;
public String totalHits;
@JsonAnySetter
public void handleUnknown(String key, Object value) {
// do something: put to a Map; log a warning, whatever
}
public List<Hits> getHits() {
return hits;
}
public void setHits(List<Hits> hits) {
this.hits = hits;
}
public String getTotalHits() {
return totalHits;
}
public void setTotalHits(String totalHits) {
this.totalHits = totalHits;
}
}
和命中类:
public class Hits {
public String number;
public String title;
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@JsonAnySetter
public void handleUnknown(String key, Object value) {
// do something: put to a Map; log a warning, whatever
}
}
所有其他属性都映射正确,但不是包含命中的列表。都是空的。我怎样才能映射它以使其正确?
谢谢!