onizukaspm / json-simple

Automatically exported from code.google.com/p/json-simple
Apache License 2.0
0 stars 0 forks source link

when putting java.sql.Timestamp it does not convert to string resulting invalid json #26

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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)

Original issue reported on code.google.com by toma%rulez.org@gtempaccount.com on 5 Jun 2010 at 3:06

GoogleCodeExporter commented 9 years ago
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.

Original comment by fangyid...@gmail.com on 6 Jun 2010 at 6:08

GoogleCodeExporter commented 9 years ago
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

Original comment by lukas.eder@gmail.com on 30 Jun 2011 at 12:58

GoogleCodeExporter commented 9 years ago
Issue 58 has been merged into this issue.

Original comment by jon.cham...@gmail.com on 10 Aug 2013 at 4:55

GoogleCodeExporter commented 9 years ago
Issue 63 has been merged into this issue.

Original comment by jon.cham...@gmail.com on 10 Aug 2013 at 4:56

GoogleCodeExporter commented 9 years ago
Issue 27 has been merged into this issue.

Original comment by jon.cham...@gmail.com on 10 Aug 2013 at 4:59

GoogleCodeExporter commented 9 years ago
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).

Original comment by ober...@civicscience.com on 4 Mar 2014 at 6:38