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

JSON serialization of infinity/NAN creates value that cannot be deserialized #33

Open
noelwelsh opened this issue Nov 8, 2011 · 4 comments

Comments

@noelwelsh
Copy link
Collaborator

Serializing a Double containing positive or negative infinity (and presumably NaN as well) creates a value that cannot then be deserialized. The JSON spec, in it's infinite wisdom, neglected to cover these cases and no common solution appears to have arisen. (It seems that browsers render these as null (/sigh) but this doesn't appear to be widely adopted.) I think BlueEyes JSON should at least be capable of deserializing all data that it serializes.

To reproduce:

val bogus = pretty( render( ("mf", Double.PositiveInfinity) ) )
val bogus = pretty( render( ("mf", Double.PositiveInfinity) ) )
bogus: String =
{
"mf":Infinity
}

scala> JsonParser.parse(bogus)
JsonParser.parse(bogus)
blueeyes.json.JsonParser$ParseException: unknown token I
Near: {
"mf":Infinity
}
at blueeyes.json.JsonParser$Parser.fail(JsonParser.scala:230)
at blueeyes.json.JsonParser$Parser.nextToken(JsonParser.scala:325)
at blueeyes.json.JsonParser$$anonfun$4.apply(JsonParser.scala:188)
at blueeyes.json.JsonParser$$anonfun$4.apply(JsonParser.scala:142)
at blueeyes.json.JsonParser$.parse(JsonParser.scala:75)
at blueeyes.json.JsonParser$.parse(JsonParser.scala:46)
at .(:17)
at .()
at .(:11)
at .()
at $print()
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
at java.lang.Thread.run(Thread.java:680)

@jdegoes
Copy link
Owner

jdegoes commented Nov 9, 2011

Definitely a bug. We'll fix it right away. Thanks for reporting!

On Nov 8, 2011, at 9:39 AM, Noel Welsh wrote:

Serializing a Double containing positive or negative infinity (and presumably NaN as well) creates a value that cannot then be deserialized. The JSON spec, in it's infinite wisdom, neglected to cover these cases and no common solution appears to have arisen. (It seems that browsers render these as null (/sigh) but this doesn't appear to be widely adopted.) I think BlueEyes JSON should at least be capable of deserializing all data that it serializes.

To reproduce:

val bogus = pretty( render( ("mf", Double.PositiveInfinity) ) )
val bogus = pretty( render( ("mf", Double.PositiveInfinity) ) )
bogus: String =
{
"mf":Infinity
}

scala> JsonParser.parse(bogus)
JsonParser.parse(bogus)
blueeyes.json.JsonParser$ParseException: unknown token I
Near: {
"mf":Infinity
}
at blueeyes.json.JsonParser$Parser.fail(JsonParser.scala:230)
at blueeyes.json.JsonParser$Parser.nextToken(JsonParser.scala:325)
at blueeyes.json.JsonParser$$anonfun$4.apply(JsonParser.scala:188)
at blueeyes.json.JsonParser$$anonfun$4.apply(JsonParser.scala:142)
at blueeyes.json.JsonParser$.parse(JsonParser.scala:75)
at blueeyes.json.JsonParser$.parse(JsonParser.scala:46)
at .(:17)
at .()
at .(:11)
at .()
at $print()
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
at java.lang.Thread.run(Thread.java:680)


Reply to this email directly or view it on GitHub:
#33

@fooblahblah
Copy link
Collaborator

Curious if this was ever implemented? I have a pesky Python server returning NaN and need to deal with it :)

@jdegoes
Copy link
Owner

jdegoes commented Aug 22, 2012

Daniel has made a change that converts infinities / NaN to JNothing. Which may or may not be what you want!

On Aug 22, 2012, at 1:58 PM, Jeff Simpson wrote:

Curious if this was ever implemented? I'm have a pesky Python server return NaN and need to deal with it :)


Reply to this email directly or view it on GitHub.

@fooblahblah
Copy link
Collaborator

Yeah. That might work! Thanks.

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

No branches or pull requests

3 participants