Created
September 4, 2023 13:32
-
-
Save judepereira/b190ef1ecad3bcb6a79dd6e52878974a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private static final ObjectMapper OM = new ObjectMapper(); | |
public static String escapeString(Object o) { | |
if (o == null) { | |
return null; | |
} | |
try { | |
// The string is automatically quoted. Therefore, return a new string that | |
// doesn't contain those quotes (since the caller appends quotes themselves). | |
val bytes = OM.writeValueAsBytes(o.toString()); | |
return new String(bytes, 1, bytes.length - 2, StandardCharsets.UTF_8); | |
} catch (JsonProcessingException e) { | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment