<!--Jackson required包-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.3</version>
</dependency>
// 第1步:创建ObjectMapper对象。
// 创建ObjectMapper对象。它是一个可重复使用的对象。
ObjectMapper mapper = new ObjectMapper();
String jsonString = "{\"name\":\"Mahesh\", \"age\":21}";
// 第2步:反序列化JSON到对象。
// 从JSON对象使用readValue()方法来获取。通过JSON字符串和对象类型作为参数JSON字符串/来源。
//map json to student
Student student = mapper.readValue(jsonString, Student.class);
System.out.println(student);
// 第3步:序列化对象到JSON。
// 使用writeValueAsString()方法来获取对象的JSON字符串表示。
jsonString = mapper.writeValueAsString(student);
System.out.println(jsonString);