I have a HashMap
object which I want to convert to JsonNode
tree using com.fasterxml.jackson.databind.ObjectMapper
. What is the best w
The following will do the trick:
JsonNode jsonNode = mapper.convertValue(map, JsonNode.class);
Or use the more elegant solution pointed in the comments:
JsonNode jsonNode = mapper.valueToTree(map);
If you need to write your jsonNode
as a string, use:
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);