This functionality is available in the Gson 1.3 Release which is now
available. To get the parse tree you can do the following:
JsonParser parser = new JsonParser();
JsonElement parseTreeRootElement = parser.parse(jsonStringValue);
The nice thing about the above approach is you are not required to set
up the Gson overhead of constructing the "default" type adapter, etc.
As well, as Inder stated above, the conversion back to the string
value is not as simple as calling a "toString" on the JsonElement
object.
Hope this feature helps you,
Joel
On Mar 30, 6:12 pm, inder <
inder...@gmail.com> wrote:
> It will be more like:
>
> Gson parser = new Gson();
> JsonElement parseResult = parser.toJsonTree(someJsonString);
> MyClass obj = parser.fromJson(parseResult, MyClass.class);
>
> The following will actually not work as expected:
> String backToJson = parseResult.toString();
>
> This is because JsonElement.toString() method currently does NOT
> escape strings properly. So, if there is a string with escape
> characters, those will get inlined as is. This is filed as a bughttp://
code.google.com/p/google-gson/issues/detail?id=107