[英]How to use Jackson to deserialize an array of objects in side of an object?
How can I deserialize only the items array? 如何仅反序列化items数组?
{
"code": 200,
"bookmarks": {
"count": 2,
"items": [
{
"status": "I",
"id": "1",
"percent": 9,
"timestamp": 1462826317475
},
{
"status": "I",
"id": "2",
"percent": 10,
"timestamp": 1462909994981
}
],
"links": []
}
}
I know for an array I can do something like this: 我知道对于数组我可以做这样的事情:
List<MyClass> myObjects = mapper.readValue(jsonInput, new TypeReference<List<MyClass>>(){});
Can I specify only deserializing items? 我可以只指定反序列化项目吗?
Use ObjectReader
s at(JsonPointer)
method to specify sub-tree to bind. 使用
ObjectReader
的at(JsonPointer)
方法来指定要绑定的子树。 Something like: 就像是:
Item[] items = mapper.readerFor(Item[].class).at("/bookmarks/items").readValue();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.