基本用法
https://juejin.cn/post/6844903766915809287#heading-45
映射嵌套的JSON对象
反序列化数组或集合
String json = "[\"C\",\"C++\",\"Java\",\"Python\",\"Golang\",\"JavaScript\"]";
String[] array = mapper.readValue(json, String[].class);ArrayList<User> users = Lists.newArrayList(User.builder().username("张三").build(), User.builder().username("李四").build());
String jsonArray = objectMapper.writeValueAsString(users);
User[] userArray = objectMapper.readValue(jsonArray, User[].class);ArrayList<User> users = Lists.newArrayList(User.builder().username("张三").build(), User.builder().username("李四").build());
String jsonArray = objectMapper.writeValueAsString(users);
ArrayList<User> list = objectMapper.readValue(jsonArray, new TypeReference<>() {
});CollectionType javaType = objectMapper.getTypeFactory().constructCollectionType(List.class, User.class);
List<User> users3 = objectMapper.readValue(jsonArray, javaType);基本用法
Java 类转 json 字符串
json 字符串转 Java 类
json 转换为 JsonNode
json 转换为 Map
json 转换为 List
json 转换为 Java 类数组
最后更新于