yunussasmaz / google-gson

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

java.util.Date is serialized as null when referenced from [Container { Map<String,Object> }] #270

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Open maven based eclipse project
2. Run as java application gson.bug.MessItUp

What is the expected output? What do you see instead?

Expected:

Print the JSON of values:
Print the JSON of values:
{"creationDate":"Dec 6, 2010 2:52:26 PM"}
Print the JSON of A:
{"values":{"creationDate":"Dec 6, 2010 2:52:26 PM"}}

Actual: 
Print the JSON of values:
{"creationDate":"Dec 6, 2010 2:52:26 PM"}
Print the JSON of A:
{"values":{"creationDate":{}}}

What version of the product are you using? On what operating system?
GSON 1.6, Ubuntu 64bit. Java 1.6.

Original issue reported on code.google.com by hq4ever on 6 Dec 2010 at 1:14

Attachments:

GoogleCodeExporter commented 9 years ago
I'm attaching the patch for the issue.
I suggest to serialize map's values based on actual class (value.getClass()) 
rather then parameter type.
In this case standalone map and field (as in hq4ever's example) will be 
serialized in the same way.
Also this way we'll have more transparent way of serialization subclasses 
inside the map.
Am I missing any use cases which will be broken?

Original comment by kulik.st...@gmail.com on 10 Jan 2011 at 10:42

Attachments:

GoogleCodeExporter commented 9 years ago
This should work with Gson 1.7.

Original comment by joel.leitch@gmail.com on 13 Apr 2011 at 9:18

GoogleCodeExporter commented 9 years ago
Fixed in GSON 2.0.

Original comment by limpbizkit on 2 Oct 2011 at 3:18