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