-
Notifications
You must be signed in to change notification settings - Fork 139
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
Fix #292: decode special numbers (Infinite, NaN) #293
base: series/1.x
Are you sure you want to change the base?
Conversation
|
@fsvehla thanks for the review. I agree with your point. But
From import zio.json._
println(123.4.toJson)
println(Double.NaN.toJson)
println(Double.PositiveInfinity.toJson)
println(Double.NegativeInfinity.toJson) I get
So for more consistency, I propose in this PR an implementation that accepts NaN and Infinity. On the other side, to be in compliance with RFC7159, I think it is needed to remove the parsing of NaN and Infinity and to return an error when trying to convert NaN or Infinity into JSON. This would mean that What do you think? |
note that |
@fommil thanks for your comment. I understand your point. So I've changed the way to check and parse number in the context of double/float, and ensure encoder/decoder are invertible for those types. But this results in test "Decoder > ZIO Streams integration > decodeJsonTransducer > Newline delimited > is interruptible" to fail (any idea why?). What do you think of this approach? Note: as |
@fsarradin Please push a WIP branch and I'll have a look at the ZIO-streams transducer test |
@fsvehla thanks a lot. The last update is the WIP. But it seems that the test failure only happens on my machine!? 😅 |
OK, I’ll investigate the flaky test |
adding Please start by adding a unit test along the lines of parsing TL;DR rename BTW I'm hesitant to call this a bug. Certainly it's a nice quality of life feature. But if you take some of these JSON payloads that are being produced and try to parse them in any other library or on another platform, you'll be lucky if they decode the way you are expecting here. |
@fommil I think my new commit almost fulfills what you have specified. But still, I've the same failure with ZIO-streams transducer test.
TBH it is the source of my former confusion in this PR. Nevertheless, the problem comes from trying to match IEEE754 with numbers as described in RFC7159. As the one is not the subset of the other, I think that we have to consider two possibilities. 1/ Float or Double should not be allowed in JSON conversion. 2/ Double and Float are allowed, but developers should have to consider first the type BigDecimal to represent numbers, unless they know what they are doing :) This said, IEEE754 is a long-time and widely adopted standard. I tend to think that there might have just a few libs and platforms that does not support it. Currently, I have done tests with JSON libs like in Java (Jackson) and Python (in its SDK) and they recognize it. BTW, it's an optimistic point of view :D |
I can’t reproduce the flaky test — @fsarradin can you paste the test output? |
Here is what I get:
|
@fsvehla Hi, did you reproduce the problem? |
No, and it seems unrelated. @fsarradin this looks fine, but will have to make it into 0.2 — I’m thinking about how to manage this and will come back to this shortly. |
@fsvehla Any news maybe? |
To fix it, it seems that I've to add chars N and I in the function
checkNumber
inlexer,scala
. But it seems that something equivalent should be done for the functionskipValue
andisNumber
. For the last one, it seems that we have to add in the case the letters in NaN and Infinity.I have also added some tests.