-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add JsonNodeFeature.FAIL_ON_NAN_TO_BIG_DECIMAL_COERCION
to determine what happens on JsonNode
coercion to BigDecimal
with NaN
#4195
Conversation
NaN
to BigDecimal
coercion when DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS
enabledNaN
-> BigDecimal
coercion when DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS
enabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isNaN check is broken. It needs to be fixed first. I think it is too late in 2.16 release to do this.
Oh okay, will close for now since fixing |
Yeah, let's tackle this in 2.17 once we get 2.16.0 final out (still hoping to get Android-records module in and that's it). |
Is there a open discussion about this that I can dig into/work on, @pjfanning ? |
I don't think there is a Discussion for this yet. |
If there is one, I assume FasterXML/jackson-core#1137 would be the one? |
NaN/Infinite s not part of JSON spec. I think this is low priority and not of great benefit. Could we wait until some real world users ask for this? Jackson is complicated enough already. |
True 👍🏼. No need for proactive action. |
@pjfanning Actually there is one aspect that is within JSON spec: overflow/underflow for @JooHyukKim There are existing failures due to problems with combination of:
so this is not completely theoretical problem. |
Thank you for the explanation, @cowtowncoder!. I digged into other related issues then added a list in the PR description, to save anyone's search time. Depending on how we apprach the Turning into draft for now. Sorry for making a fuss by changing PR state 🥲. |
src/main/java/com/fasterxml/jackson/databind/cfg/JsonNodeFeature.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fasterxml/jackson/databind/cfg/JsonNodeFeature.java
Outdated
Show resolved
Hide resolved
NaN
-> BigDecimal
coercion when DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS
enabledDeserializationFeature.FAIL_ON_NAN_TO_BIG_DECIMAL_COERCION
to determine what happens on JsonNode
coercion to BigDecimal
with NaN
DeserializationFeature.FAIL_ON_NAN_TO_BIG_DECIMAL_COERCION
to determine what happens on JsonNode
coercion to BigDecimal
with NaNJsonNodeFeature.FAIL_ON_NAN_TO_BIG_DECIMAL_COERCION
to determine what happens on JsonNode
coercion to BigDecimal
with NaN
@@ -755,6 +755,12 @@ protected final JsonNode _fromFloat(JsonParser p, DeserializationContext ctxt, | |||
return _fromBigDecimal(ctxt, nodeFactory, p.getDecimalValue()); | |||
} | |||
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) { | |||
// [databind#4194] Add an option to fail coercing NaN to BigDecimal | |||
// Currently, Jackson 2.x allows such coercion, but Jackson 3.x will not | |||
if (p.isNaN() && ctxt.isEnabled(JsonNodeFeature.FAIL_ON_NAN_TO_BIG_DECIMAL_COERCION)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JooHyukKim p.isNaN is broken - I don't understand why this is merged - we need p.isNan to be fixed first - please can we revert this? FasterXML/jackson-core#1135
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code can be made to work if the code is moved to the catch block of the try - the try/catch is there because the p.isNaN does not work reliably
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code can be made to work if the code is moved to the catch block of the try - the try/catch is there because the p.isNaN does not work reliably
Right, makes sense. Thank you for providing a solution @pjfanning 🙏🏼
🔗PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pjfanning I looked through ParserBase.isNaN()
and I am not sure why you think it is broken wrt usage here.
Not only are all tests passing (but there may be gaps in coverage), but I think logic makes sense: when a NaN
value is encountered, value is immediately assigned with resetAsNaN()
; otherwise parsing is deferred.
And ParserBase.isNaN()
should not trigger parsing as double.
One thing to specifically note is that since JsonNodeDeserializer
gets to call accessors first, there should not be cases for getDoubleValue()
to get called first.
So... how specifically do you think isNaN()
is broken wrt this specific use case?
resolves #4194
Related issues
BigDecimal
numbers #1770