Skip to content

Instantly share code, notes, and snippets.

@seunggabi
Created March 21, 2020 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seunggabi/5ee4fb66d86a8896f5f38837f3699654 to your computer and use it in GitHub Desktop.
Save seunggabi/5ee4fb66d86a8896f5f38837f3699654 to your computer and use it in GitHub Desktop.
mapToJson.java
public static String mapToJson(Map map, boolean isPretty) {
ObjectMapper mapper = new ObjectMapper();
try {
return isPretty ?
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map) :
mapper.writeValueAsString(map);
} catch (JsonProcessingException e) {
return "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment