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

JSONFormat.defaultFormat doesn't handle null values #5092

Closed
scabug opened this issue Oct 19, 2011 · 8 comments
Closed

JSONFormat.defaultFormat doesn't handle null values #5092

scabug opened this issue Oct 19, 2011 · 8 comments

Comments

@scabug
Copy link

scabug commented Oct 19, 2011

import scala.util.parsing.json.JSONObject
println(new JSONObject(Map("test" -> null)))

will throw an exception:

java.lang.NullPointerException
        at scala.util.parsing.json.JSONFormat$$anonfun$1.apply(Parser.scala:59)
        at scala.util.parsing.json.JSONFormat$$anonfun$1.apply(Parser.scala:55)
        at scala.util.parsing.json.JSONObject$$anonfun$toString$1.apply(Parser.scala:96)
        at scala.util.parsing.json.JSONObject$$anonfun$toString$1.apply(Parser.scala:96)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
        at scala.collection.immutable.Map$Map1.foreach(Map.scala:118)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:194)
        at scala.collection.immutable.Map$Map1.map(Map.scala:106)
        at scala.util.parsing.json.JSONObject.toString(Parser.scala:96)
        at scala.util.parsing.json.JSONType.toString(Parser.scala:33)
        at java.lang.String.valueOf(String.java:2826)
        at java.io.PrintStream.println(PrintStream.java:771)
        at scala.Console$.println(Console.scala:244)

This is works in 2.8, so it's clearly a regression.

@scabug
Copy link
Author

scabug commented Oct 19, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5092?orig=1
Reporter: Zsombor Gegesy (gzsombor)
Affected Versions: 2.9.0, 2.9.1, 2.9.2
See #6571

@scabug
Copy link
Author

scabug commented Jul 16, 2012

David Leppik (dleppik) said:
It appears that the problem is that scala.util.parsing.json.JSONFormat (line 55 in Parser.scala) is missing one case, which should be:

case null => "null"

This is important to fix, since nulls are commonly used in JSON, including in third-party JavaScript libraries, so proper handling of nulls is necessary. (A more Scala-ish solution would be to format None as null, and then parse JSON nulls into None.)

@scabug
Copy link
Author

scabug commented Feb 20, 2013

@adriaanm said:
see #6571 (planning to deprecate in 2.11)

@scabug
Copy link
Author

scabug commented Dec 11, 2013

@adriaanm said:
json parsing has been deprecated in the parser combinators library -- please use spray-json, play-json,...

@scabug scabug closed this as completed Dec 11, 2013
@scabug
Copy link
Author

scabug commented Jun 3, 2015

ChangZhuo Chen (陳昌倬) (czchen) said:
What is the status of this issue?

The deprecated annotation is removed in [0], and #6571 said "closing as meta-bug – the individual tickets will still be fixed if they haven't already". However, this issue still happens in Scala 2.10.5. So I am not sure it is deprecated or revived right now? Please provide the information so that we can decide continuously use it or change to third-party library, thanks.

[0] scala/scala-parser-combinators@ff68f4b

@scabug
Copy link
Author

scabug commented Jun 11, 2015

@adriaanm said:
I would not recommend using the json parser in scala-parser-combinators. Which alternative is suitable for you depends on your requirements -- there are almost too many to name. Here's a good overview: https://github.com/propensive/rapture-json

@scabug
Copy link
Author

scabug commented Jun 13, 2015

@soc said:
I have no idea why it was undeprecated, I even explicitly wrote that instead of undeprecating the JSON part, the rest which hasn't been deprecated yet should also be deprecated, and people agreed. (scala/scala-parser-combinators#32)

Maybe the merge was an oversight?

@scabug
Copy link
Author

scabug commented Jun 17, 2015

@adriaanm said:
Sounds likely to be a mistake, yes.

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

2 participants