1.pom.xml中引入依赖包

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.54</version>
</dependency>
2.控制类中引入
import com.alibaba.fastjson.JSON;
3.类型转换

// 将 Map 转换为 实体类
User user = JSON.parseObject(JSON.toJSONString(user01), User.class);
System.out.println(user);
// 将 实体类 转换为 Map
Map map = JSON.parseObject(JSON.toJSONString(user), Map.class);
System.out.println(map);
4.转换成功

网友评论