javastringescapeutils

What is the difference between unescapeJava and unescapeJson from StringEscapeUtils


As per the StringEscapeUtils documentation, looks like both these methods unescapeJson and unescapeJava does the similar thing.

I tried using both methods it works fine as below:

Example:

String input = "{\"key\":\"ab\u2019cd\"}"
System.out.println(unescapeJava(input)); // outputs: {"key":"ab’cd"}
System.out.println(unescapeJson(input)); // outputs: {"key":"ab’cd"}

Both of these statements print exactly same output. So, what is the difference and when to use which method?


Solution

  • They are the same, as you can see in the sources:

    public static final CharSequenceTranslator UNESCAPE_JSON = UNESCAPE_JAVA;