Convert Java Object to JSON using Jackson

Jackson is a easy to use API that can help in the Java to/from JSON transformation.
In this post lets see how to convert java object to json using Jackson.

Add Jackson dependency

Please note we are using jackson 2 in our examples
The latest Jackson version during writing this post was 2.8.3

If you are not using Maven you will need to download 3 jars
1. Jackson Databind 2.8.3 jar
2. Jackson Core 2.8.3 jar
3. Jackson Annotations 2.8.3 jar

Now lets start the example. First we will create a Employee Class

Now the Class that will convert Java to JSON

A JSON file will be created with following data

Writing a Java List into JSON

Lets change the above code and add a List of Employee instead of a single employee. Then we will write this List into JSON and see the output