-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
When calling valueToTree
on a mapper with enabled USE_BIG_DECIMAL_FOR_FLOATS
, it produces NumberFormatException while trying to convert NaN to BigDecimal.
ObjectMapper m = new ObjectMapper();
m.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
Object o = new Object() {
private double x = Double.NaN;
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
};
JsonNode tree = m.valueToTree(o);
System.out.println(tree);
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
and NumberType.DOUBLE
are tested for NaN/Infinity before calling getDecimalValue()
. If positive, USE_BIG_DECIMAL_FOR_FLOATS should be ignored.
Metadata
Metadata
Assignees
Labels
No labels