Gson.toJson object contains url

I am using the Gson.toJSON method. My pojo contains one of the attributes as a URL string. The strange thing is, the Gson converter changes the URL characters

output: /myApp/myAction.html?method\u003drouter\u0026cmd\u003d1

expected result: /myApp/myAction.html?method=router&cmd=1

+7
source share
1 answer

Build your Gson instance as follows:

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

Disabling HTML escaping will prevent the GSON space character from being encoded as \ u0026.

+17
source

All Articles