'Gson.toJson object contain URL

I am using Gson.toJSON method. My pojo contains one of attribute as URL string. Strange thing is Gson converter changes URL characters

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

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



Solution 1:[1]

Create your Gson instance like this:

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

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ser