What is the difference between unescapeJava and unescapeJson from StringEscapeUtils

873 views Asked by At

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?

1

There are 1 answers

1
fracz On BEST ANSWER

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

public static final CharSequenceTranslator UNESCAPE_JSON = UNESCAPE_JAVA;