In this Jackson Tree Model Example, we will learn how to convert Java Object to JSON and vice-versa ( JSON to Java object). Jackson Tree Model creates a tree representation of a JSON similar to DOM Tree. Hence it is possible to traverse through each node. Jackson provides JsonNode API through we will be accessing the individual node using the node name.The readTree and writeTree methods of the Jackson ObjectMapper is used to read and write JSON tree.
In my previous article we have learnt How to read JSON file in Java, now let’s see how we can write JSON Object to File in Java. Here also we will be using the JSON.simple library download the json-simple-1.1.1.jar (or) if you are running on maven add the below dependency to your pom.xml
<dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency>
What is JSON ?