Podría alguien sugerir por qué esto está ocurriendo ...problemas con el uso de Gson agradable para la impresión JSON cadena
Tengo un poco de código para imprimir bastante poco de JSON. Para hacer esto, estoy haciendo uso de Gson library.
Sin embargo, mientras tanto, por lo general funciona bien, no parece que se muestren correctamente algunos caracteres. Aquí es un simple trozo de código que muestra el problema:
//Creating the JSON object, and getting as String:
JsonObject json = new JsonObject();
JsonObject inner = new JsonObject();
inner.addProperty("value", "xpath('hello')");
json.add("root", inner);
System.out.println(json.toString());
//Trying to pretify JSON String:
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser parser = new JsonParser();
JsonElement je = parser.parse(json.toString());
System.out.println(gson.toJson(je));
La salida del código anterior es:
{"root":{"value":"xpath('hello')"}}
{
"root": {
"value": "xpath(\u0027hello\u0027)"
}
}
¿Cómo podría solucionar el anterior?