Parsing a subset of JSON in Java using Jackson

ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree("... your JSON ...");

Using the JsonNode object you can then call get("my").get("deep").get("structure") to get the node you want.

Once you got your hands on that node, a simple call to mapper.treeToValue(myDeepJsonNode, Telephone[].class) will get you your array ofTelephone. You can get a list using a TypeReference as well.

To get to your deep JsonNode you can also use the findValue and findPath methods.

The Javadoc: https://fasterxml.github.io/jackson-databind/javadoc/2.2.0/com/fasterxml/jackson/databind/JsonNode.html

Tags:

Java

Json

Jackson