是否可以将Java对象直接转换为JsonNode-Object?
我发现解决此问题的唯一方法是将Java对象转换为String,然后转换为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);