New issue 348 by ray.may...@gmail.com: Serializing and Deserializing
Generic Types - toJson() works!
http://code.google.com/p/google-gson/issues/detail?id=348
What steps will reproduce the problem?
1. Write a vanilla java class and declare a field of type List<String>
2. Populate the list with some arbitrary string values and call toJson()
3. It serializes the object and generates a correctly formatted JSON string
What is the expected output? What do you see instead?
It should throw a runtime exception as per the user guide
What version of the product are you using? On what operating system?
1.7.1
Please provide any additional information below.
Either something is wrong with my code / the user guide needs to be updated
Updated
What is the expected output? What do you see instead?
Expected output - runtime exception
Actual output - correct JSON string
OS - Windows XP
You're reporting that GSON works too well? Why don't I fix the docs that
claim we don't support generics. Please point me at these docs.
Here is the link
https://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and-Deserializing-Gener
And the following works for me (contrary to what the doc says)
List<String> myStrings = new List<String>();
gson.toJson(myStrings); // Will cause a runtime exception
The behaviour of lib is as per documentation. I feel u are confused between
serialization and deseralization.
I quto from docs ....."You can serialize the collection with Gson without
doing anything specific: toJson(collection) would write out the desired
output.
However, deserialization with fromJson(json, Collection.class) will not
work since Gson has no way of knowing how to map the input to the
types. " ..
What u are doing is serialization . Docs talk of deserialization