Issue 538 in google-gson: Date format is not respected when serializing map with Date as key

15 views
Skip to first unread message

googl...@googlecode.com

unread,
Oct 28, 2013, 1:43:04 PM10/28/13
to google-gson...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 538 by mbrzezi...@gmail.com: Date format is not respected when
serializing map with Date as key
http://code.google.com/p/google-gson/issues/detail?id=538

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

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

googl...@googlecode.com

unread,
May 27, 2014, 1:06:46 PM5/27/14
to google-gson...@googlegroups.com

Comment #1 on issue 538 by sean...@gmail.com: Date format is not respected
when serializing map with Date as key
http://code.google.com/p/google-gson/issues/detail?id=538

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.

googl...@googlecode.com

unread,
Sep 5, 2014, 3:57:47 AM9/5/14
to google-gson...@googlegroups.com

Comment #2 on issue 538 by omickr...@gmail.com: Date format is not
respected when serializing map with Date as key
https://code.google.com/p/google-gson/issues/detail?id=538

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.

googl...@googlecode.com

unread,
Sep 17, 2014, 6:57:08 AM9/17/14
to google-gson...@googlegroups.com

Comment #3 on issue 538 by ftoscano...@gmail.com: Date format is not
respected when serializing map with Date as key
https://code.google.com/p/google-gson/issues/detail?id=538

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

googl...@googlecode.com

unread,
Jul 2, 2015, 9:19:08 AM7/2/15
to google-gson...@googlegroups.com

Comment #4 on issue 538 by muaddib....@gmail.com: Date format is not
respected when serializing map with Date as key
https://code.google.com/p/google-gson/issues/detail?id=538

Same problem. gson 2.2.2
Reply all
Reply to author
Forward
0 new messages