object to json java jackson code example
Example 1: how to convert json to java object
Jackson Data-bind depdendency that take care of
Converting between
JSON to Java Object
and
Java Object to JSON
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.0</version>
</dependency>
Example 2: jackson object to json
ObjectMapper objectMapper = new ObjectMapper();
Car car = new Car("yellow", "renault");
objectMapper.writeValueAsString(car);
Example 3: jackson object to json
val objectMapper = ObjectMapper()
val car = Car("yellow", "renault")
objectMapper.writeValueAsString(car)