Does anyone know of a library function to escape and surround a string value of an object with quotes unless it is null?
For example, the function should process:
"hello"as"\"hello\""nullas"null"Long.valueOf(2L)as"\"2\""""as"\"\"""I\'m \"quoted\""as"\"I\\\'m \\\"quoted\\\""
Clearly this is trivial to implement in Java, but I’m looking for a function in an existing library (e.g. JDK, Commons Lang, Spring …) I’d be surprised if this hasn’t been done before.
For reference, this is for converting objects to JavaScript strings.
Forget the Quoting, really. If you want to write Java to JS, use Jackson:
If you need extra handlers to format as JS, extend ObjectMapper with your desired needs
Thank you come again