yuikns / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Not able to deserialize. #132

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using gson-1.3.jar.

I'm serializing my object using gson lib and i get the proper json string.
But while deserializing i get following exception:
Map objects need to be parameterized unless you use a custom serializer.

Here is my code:
public class A {
    Map map; //and getter and setter for this
}

//in main method of some other class
    Map m=new HashMap();
    m.put("entry1", "value1");

    A a=new A();
        a.setMap(m);

        //serialize
    Gson gson = new Gson();
    String jsonString=gson .toJson(a);

    //deserialize
    A newA =gson .fromJson(jsonString, A.class);
    System.out.println("Map is:"+newA);

Lee

b.setProp("prop");

Original issue reported on code.google.com by leenabo...@gmail.com on 7 Jul 2009 at 6:21

GoogleCodeExporter commented 9 years ago
Please assume that the map which I'm using stores the different types of object 
so I
really cannot use the generics. 
I guess and this is not supported by gson.
If not then also please let me know when will it be available and provide the
solution for above.

thanks,
Lee

Original comment by leenabo...@gmail.com on 7 Jul 2009 at 6:26

GoogleCodeExporter commented 9 years ago
Right now this is not supported by Gson.  The JSON output does not contain type
information in the output so we are unable to deserialize the objects back into 
a map
form.

For now, I do not see us adding this feature to Gson; however, you should be 
able to
write your own custom serializer and deserializer to drop type information into 
your
output so that you will be able to serialize the value back into Java.

Original comment by joel.leitch@gmail.com on 23 Sep 2009 at 6:52