准备条件: 创建Person对象
使用步骤:
- 导入Json相关Jar包
- 创建Jackson核心对象ObjectMapper
- 调用ObjectMapper的相关方法进行转换
@Test
public void test2() throws Exception {
//初始化Json字符串
String json ="{\"name\":\"张三\",\"age\":18,\"gender\":\"男\"}\n";
//创建ObjectMapper对象
ObjectMapper mapper = new ObjectMapper();
//转换为Java对象
Person person = mapper.readValue(json, Person.class);
System.out.println(person);
}