Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以直接将 Java 对象转换为 JsonNode 对象?
我发现解决此问题的唯一方法是将 Java 对象转换为字符串,然后再转换为 JsonNode:
ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(object); JsonNode jsonNode = mapper.readTree(json);
从 Jackson 1.6 开始,您可以使用:
JsonNode node = mapper.valueToTree(map);
或者
JsonNode node = mapper.convertValue(object, JsonNode.class);
资料来源:有没有办法将pojo直接序列化为treemodel?