场景说明
最近在写一个服务,经常用到调别人接口得到json,然后需要转换为 指定bean,记录一下常用工具类
引入依赖
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> </dependency>
示例
bean
@Data public class User { private Integer id; private String name; private List<String> books; }
转换
@Test public void testjson() { User user = new User(); user.setId(1001); user.setName("金庸"); ArrayList<String> books = new ArrayList<>(); books.add("飞"); books.add("雪"); books.add("连"); books.add("天"); books.add("射"); books.add("白"); books.add(" 标签:Java,name,bean,json,books,User,add,id,1001 From: https://www.cnblogs.com/wdh01/p/18071677