Jackson用的不多,这里先记一下。
https://stackoverflow.com/questions/48287292/how-do-you-convert-a-jackson-jsonnode-to-a-list-of-some-user-defined-object
1 2 3 4 5
| { "objects":"that", "I":"dont care about", "objectsiwant":[{object1, object2,...}] }
|
使用readerFor或readerForListOf
1 2 3 4 5 6 7
| ObjectMapper mapper = new ObjectMapper(); JsonNode rootNode = mapper.readTree(json); JsonNode internalNode = rootNode.path("objectsiwant");
List<MyPojo> myPojoList = mapper.readerFor(new TypeReference<List<MyPojo>>(){}).readValue(internalNode);
List<MyPojo> myPojoList = mapper.readerForListOf(MyPojo.class).readValue(internalNode);
|