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

Issue regarding the fallback alternative in JSONValue.toJSONString #27

Closed
GoogleCodeExporter opened this issue Jan 20, 2016 · 11 comments
Closed

Comments

@GoogleCodeExporter
Copy link

Hi,

Right now the fallback of JSONValue.toJSONString is:

         return value.toString();

Wouldn't something like the following be better, since the current
implementation can render invalid JSON with a bad toString?

         return "\"" + escape(value.toString() + "\"";

Original issue reported on code.google.com by anders.r...@gmail.com on 30 Jun 2010 at 1:16

@GoogleCodeExporter
Copy link
Author

Looks sane to me too. Blindly returning result of value.toString() is a bug 
IMO. Any way to produce valid JSON is much better than this. Either escape it 
like suggested or return null or "undefined" or whatever.

Original comment by fano...@gmail.com on 14 Jul 2010 at 12:03

@GoogleCodeExporter
Copy link
Author

Original comment by fangyid...@gmail.com on 14 Jul 2010 at 1:10

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

@GoogleCodeExporter
Copy link
Author

Issue 18 has been merged into this issue.

Original comment by fangyid...@gmail.com on 14 Jul 2010 at 1:15

@GoogleCodeExporter
Copy link
Author

Oops, i didn't notice this one, i'm sorry, issue #33 is a duplicate :_(
Anyway, the problem seems to affect writeJSONString as well.
Here's a small patch that seems to work for me...

bye.

Original comment by sanita.c...@gmail.com on 4 Aug 2010 at 9:11

Attachments:

@GoogleCodeExporter
Copy link
Author

Issue 33 has been merged into this issue.

Original comment by fangyid...@gmail.com on 5 Aug 2010 at 12:15

@GoogleCodeExporter
Copy link
Author

hello. I just wanted to ask, if there will be a next version of the json-simple 
library with this enhancement in the near future. 

Original comment by berndhub...@googlemail.com on 21 Feb 2011 at 10:44

@GoogleCodeExporter
Copy link
Author

Not sure what does "near future" mean to you, but I do have a plan making some 
improvement of json-simple this year. Will let your guys know once I have any 
update.

Thanks,
Yidong. 

Original comment by fangyid...@gmail.com on 22 Feb 2011 at 4:49

@GoogleCodeExporter
Copy link
Author

thanks for the info. The library works also very well in our project, but now 
we are facing the problem that "java.util.Date" classes are not serialized with 
the "", so we get something like this in our json strings:

"birthdate" : Thu Jul 01 00:00:00 CET 1976

But we need something like this, so we can deserialize the date again:

"birthdate" : "Thu Jul 01 00:00:00 CET 1976"

The patch provided here seems to work, but it would be better if the official 
json-simple lib provides this feature/enhancement.

Maybe there is also an other way to format a java.util.date correctly, without 
applying this patch ?


Original comment by berndhub...@googlemail.com on 24 Feb 2011 at 9:28

@GoogleCodeExporter
Copy link
Author

To make it work without modifying anything in json-simple, you may want to call 
toString() of java.util.Date before putting it in a java.util.Map:

json.put("key", aDate.toString())

Thanks,
Yidong.

Original comment by fangyid...@gmail.com on 24 Feb 2011 at 11:22

@GoogleCodeExporter
Copy link
Author

thanks, this seems like a good alternative.

B.Huber

Original comment by berndhub...@googlemail.com on 25 Feb 2011 at 12:46

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Duplicate

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