-
-
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
Ignore USE_BIG_DECIMAL_FOR_FLOATS for NaN/Infinity #1028
Comments
Sounds like a bug. I am not sure what would be the best way to deal with this: quietly swallowing the problem may not be the best way to deal with this, given that caller would be expecting |
The idea is that it must be possible to process JSON handling NaN/Infinity as Double and others as BigDecimal to assure 100% precision retention. |
@lightoze unfortunately I am not sure if this is fully possible -- since, as per say: http://stackoverflow.com/questions/28065158/java-bigdecimal-and-double-nan there is no way to actually store these values in I will send a question on |
Right, I also think it's not currently possible. The idea is to deserialize decimals as BigDecimal, but NaN as Double/Float. Of course, this applies only to the case when we deserialize to an Object or JsonNode, etc. |
Perhaps it is possible to improve things relatively easily by small modifications to |
There is also similar logic in |
When calling
valueToTree
on a mapper with enabledUSE_BIG_DECIMAL_FOR_FLOATS
, it produces NumberFormatException while trying to convert NaN to BigDecimal.In my data I need BigDecimal in some places where exact precision is required. Because Jackson does not automatically use BigDecimal for values which will not fit into Double (like it does for integers), I have to enable USE_BIG_DECIMAL_FOR_FLOATS, but still have to use doubles (which can be NaN) in other parts of the data structure.
I suggest that tokens with
NumberType.FLOAT
andNumberType.DOUBLE
are tested for NaN/Infinity before callinggetDecimalValue()
. If positive, USE_BIG_DECIMAL_FOR_FLOATS should be ignored.The text was updated successfully, but these errors were encountered: