Skip to content

Instantly share code, notes, and snippets.

@HoweChen
Last active April 3, 2020 08:54
Show Gist options
  • Save HoweChen/c0c1e056f3c581bdab9458040746608d to your computer and use it in GitHub Desktop.
Save HoweChen/c0c1e056f3c581bdab9458040746608d to your computer and use it in GitHub Desktop.
[POJO to json String] #Java
public String toString() throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String result;
try {
result = mapper.writeValueAsString(this);
} catch (JsonProcessingException e) {
throw new Exception("Cannot transfer backend server info to json string");
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment