First Application Jackson
Before understanding the concepts of Jackson in detail, we will first understand a basic Jackson application to get a basic idea of Jackson's code.
We will create an Employee class in our first application and then create a JSON string of Employee details. Later, we will desterilize the Employee string to the Employee object, and vice-versa.
The JSON string is as follows:
Steps to Remember:
These are some of the following steps that are important to be considered here.
Create an instance of ObjectMapper class that should be reusable.
When we deserialize JSON to object, it is required to use the readValue() method. This method returns the Object representation of the given JSON string. Pass json string/ source of json string and object type as a parameter. We map JSON to object in the following way:
When we serialize Object to JSON, it is required to use the writeValueAsString() method. This method returns string representation of the given Object. We convert Object to JSON in the in following way: