简体   繁体   中英

How to use Jackson to deserialize an array of objects in side of an object?

How can I deserialize only the items array?

{
 "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. Something like:

Item[] items = mapper.readerFor(Item[].class).at("/bookmarks/items").readValue();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM