brbtsl
brbtsl

Reputation: 332

Gson failure to conver symbols

I am using the Gson function toJson for the =, > and < operators, and in the final string they are interpreted as \u003e.

Is there a special feature I need to add or take care of?

Upvotes: 3

Views: 864

Answers (1)

Pragmateek
Pragmateek

Reputation: 13374

You should disable HTML escaping, here is a sample that illustrates it:

Gson gson1 = new Gson();

String s1 = gson1.toJson("<>");

Gson gson2 = new GsonBuilder().disableHtmlEscaping().create();

String s2 = gson2.toJson("<>");

s1: "\u003c\u003e"

s2: "<>"

Upvotes: 5

Related Questions