The following will do the trick:
JsonNode jsonNode = mapper.convertValue(map, JsonNode.class);
Or use the more elegant solution mentioned in the comments :
JsonNode jsonNode = mapper.valueToTree(map);
If you need to write jsonNode as a string, use:
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);
Cassio mazzochi molin
source share