jackson object to json
snippet in kotlin

jackson object to json

user936

val objectMapper = ObjectMapper()
val car = Car("yellow", "renault")
objectMapper.writeValueAsString(car)

convert json to object jackson

user7992

ObjectMapper objectMapper = new ObjectMapper();

String carJson =
    "{ \"brand\" : \"Mercedes\", \"doors\" : 5 }";

try {
    Car car = objectMapper.readValue(carJson, Car.class);

    System.out.println("car brand = " + car.getBrand());
    System.out.println("car doors = " + car.getDoors());
} catch (IOException e) {
    e.printStackTrace();
}

jackson object to json

user3722

ObjectMapper objectMapper = new ObjectMapper();
Car car = new Car("yellow", "renault");
objectMapper.writeValueAsString(car);