How to convert HashMap to JsonNode with Jackson?

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);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)