Issue 26 in json-simple: when putting java.sql.Timestamp it does not convert to string resulting invalid json

28 views
Skip to first unread message

json-...@googlecode.com

unread,
Jun 5, 2010, 11:07:34 AM6/5/10
to json-...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 26 by to...@rulez.org: when putting java.sql.Timestamp it does not
convert to string resulting invalid json
http://code.google.com/p/json-simple/issues/detail?id=26

What steps will reproduce the problem?
1. I fetched the data from jdbc
2. Map fields = new LinkedHashMap(); fields.put("Time", rs.getObject(i))
3. then getting json: ... "Time":2003-03-12 12:23:14.363

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

I'd expect "Time":"2003-03-12 12:23:14.363" however the locales could be
errorous, I understand.

What version of the product are you using? On what operating system?

json-simple-1.1.jar

Please provide any additional information below.

java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)


json-...@googlecode.com

unread,
Jun 6, 2010, 2:09:04 AM6/6/10
to json-...@googlegroups.com
Updates:
Status: Accepted
Labels: -Type-Defect Type-Enhancement

Comment #1 on issue 26 by fangyidong: when putting java.sql.Timestamp it

does not convert to string resulting invalid json
http://code.google.com/p/json-simple/issues/detail?id=26

Classes not in the table of the following link are not supposed to be
supported:
http://code.google.com/p/json-simple/wiki/MappingBetweenJSONAndJavaEntities

But since date/time is used frequently, it can be considered an enhancement.

To make it work, you might want to convert it into a String before putting
it in the map:
fields.put("Time", String.valueOf(rs.getObject(i)))

Thanks.


json-...@googlecode.com

unread,
Jun 30, 2011, 8:59:20 AM6/30/11
to json-...@googlegroups.com

Comment #2 on issue 26 by lukas.e...@gmail.com: when putting
java.sql.Timestamp it does not convert to string resulting invalid json
http://code.google.com/p/json-simple/issues/detail?id=26

I would agree with the OP's opinion. Any of these types should be supported
and serialised as String. These ones already have a meaningful toString()
method:

- java.sql.Time
- java.sql.Timestamp
- java.sql.Date

This one could be converted into java.sql.Timestamp:

- java.util.Date

json-...@googlecode.com

unread,
Aug 10, 2013, 12:56:40 AM8/10/13
to json-...@googlegroups.com

Comment #3 on issue 26 by jon.cham...@gmail.com: when putting
java.sql.Timestamp it does not convert to string resulting invalid json
http://code.google.com/p/json-simple/issues/detail?id=26

Issue 58 has been merged into this issue.

--
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

json-...@googlecode.com

unread,
Aug 10, 2013, 12:57:40 AM8/10/13
to json-...@googlegroups.com

Comment #4 on issue 26 by jon.cham...@gmail.com: when putting
java.sql.Timestamp it does not convert to string resulting invalid json
http://code.google.com/p/json-simple/issues/detail?id=26

Issue 63 has been merged into this issue.

json-...@googlecode.com

unread,
Aug 10, 2013, 1:01:40 AM8/10/13
to json-...@googlegroups.com

Comment #5 on issue 26 by jon.cham...@gmail.com: when putting
java.sql.Timestamp it does not convert to string resulting invalid json
http://code.google.com/p/json-simple/issues/detail?id=26

Issue 27 has been merged into this issue.

json-...@googlecode.com

unread,
Mar 4, 2014, 1:38:41 PM3/4/14
to json-...@googlegroups.com

Comment #6 on issue 26 by ober...@civicscience.com: when putting
java.sql.Timestamp it does not convert to string resulting invalid json
http://code.google.com/p/json-simple/issues/detail?id=26

For what it's worth, I wish the library would throw an exception in the
Object case, as it is unknown if the JSON produced by calling
Object.toString() is valid JSON. I'm a believer in "fail-fast", rather
than get bitten by badly encoded JSON later (which is what happened to me).
Reply all
Reply to author
Forward
0 new messages