Last active
April 3, 2020 08:54
-
-
Save HoweChen/c0c1e056f3c581bdab9458040746608d to your computer and use it in GitHub Desktop.
[POJO to json String] #Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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