Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoogleCodeExporter opened this issue Nov 30, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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

  • Changed state: Accepted
  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

Issue 58 has been merged into this issue.

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

@GoogleCodeExporter
Copy link
Author

Issue 63 has been merged into this issue.

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

@GoogleCodeExporter
Copy link
Author

Issue 27 has been merged into this issue.

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

@GoogleCodeExporter
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant