import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class PlayJsonExample {
public static void main(String[] args) {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode objectNode = objectMapper.createObjectNode();
objectNode.put("name", "John");
objectNode.put("age", 30);
String jsonString = objectMapper.writeValueAsString(objectNode);
System.out.println(jsonString);
JsonNode jsonNode = objectMapper.readTree(jsonString);
String name = jsonNode.get("name").asText();
int age = jsonNode.get("age").asInt();
System.out.println("Name: " + name);
System.out.println("Age: " + age);
}
}
<dependencies>
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play-json_2.12</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>