java - GSON issue with String -
string s = "m\\"+"/m\\/m/m/m/m/m"; linkedhashmap<string, string> hm = new linkedhashmap<>(); hm.put("test", s); system.out.println(hm+" hash map = "+hm.tostring());
fine output {test=m\/m\/m/m/m/m/m} hash map = {test=m\/m\/m/m/m/m/m}
string s2 = new gson().tojson(hm.tostring()); system.out.println("json result "+s2);
not fine output json result "{test\u003dm\\/m\\/m/m/m/m/m}"
is gson going mad or doing wrong? happening back slashes , u003d
appears? knew there exists bug of nature long time ago resolved. how can resolve issue? in advance.
the =
sign encoded \u003d.
hence need use disablehtmlescaping().
you can use
gson gson = new gsonbuilder().disablehtmlescaping().create(); string s2 = gson.tojson(hm.tostring());
for \/
turning \\/
issue, solution
s2.replace("\\\\", "\\");
Comments
Post a Comment