dfmotty / google-gson

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

Date format is not respected when serializing map with Date as key #538

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Crete Map<Date,Object> and populate with random data
2. Create Gson using GsonBuilder and setDateFormat("any format")
3. Serialize map to json.

What is the expected output? What do you see instead?
I expect keys to be serialized using date format, but I see that keys are 
converted to strings using Date.toString() which uses generic "EEE MMM dd 
HH:mm:ss z yyyy" format

What version of the product are you using? On what operating system?
2.2.4 from Maven,Ubuntu Linux

Original issue reported on code.google.com by mbrzezi...@gmail.com on 28 Oct 2013 at 5:42

GoogleCodeExporter commented 9 years ago
i got the same issue. if date is a field of the object, it will be fine. if it 
is inside a map, then only default date format. even customized date sterilizer 
doesnt work.

Original comment by sean...@gmail.com on 27 May 2014 at 5:06

GoogleCodeExporter commented 9 years ago
Got the same issue.

Even when the Date is value in the map, it's serialized with the date format.
But when using Date as a key of the map, toString is used.

Original comment by omickr...@gmail.com on 5 Sep 2014 at 7:57

GoogleCodeExporter commented 9 years ago
Same issue in Map<String, Object> when value is java.util.Date
serialization is ok, deserialization returns a String.
gson 2.2.4

Original comment by ftoscano...@gmail.com on 17 Sep 2014 at 10:56