I am using GSON to serialize my object. But some reason, it is not escaping certain unicode chars.
Gson gson = new Gson();
System.out.println(gson.toJson("™"));
System.out.println(Character.codePointAt("™", 0) );
System.out.println(Character.codePointAt("™", 1) );
Output:
"™"
194
8482
Is there a setting to ensure that the chars get escaped?
There is no reason to escape unicode characters as they're allowed in JSON strings.
From json.org :

If you have problems sending your JSON to the browser, check your HTTP headers are set to UTF-8.
If you really want to escape unicode characters as in Java, you might use apache commons's StringEscapeUtils#escapeJava but you probably shouldn't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With