Skip to content

Commit

Permalink
issue-1770 - big number not returned as DecimalNode
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Nov 7, 2023
1 parent 604cdbd commit cd3cc18
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,6 @@ protected final JsonNode _fromFloat(JsonParser p, DeserializationContext ctxt,
return _fromBigDecimal(ctxt, nodeFactory, p.getDecimalValue());
}
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
// 20-May-2016, tatu: As per [databind#1028], need to be careful
// (note: JDK 1.8 would have `Double.isFinite()`)
if (p.isNaN()) {
return nodeFactory.numberNode(p.getDoubleValue());
}
return _fromBigDecimal(ctxt, nodeFactory, p.getDecimalValue());
}
if (nt == JsonParser.NumberType.FLOAT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.databind.*;

import java.math.BigDecimal;

/**
* Basic tests for {@link JsonNode} implementations that
* contain numeric values.
Expand All @@ -16,11 +18,11 @@ public class NumberNodes1770Test extends BaseMapTest
// `DoubleNode` being used even tho `BigDecimal` could fit the number.
public void testBigDecimalCoercion() throws Exception
{
final String value = "7976931348623157e309";
final JsonNode jsonNode = MAPPER.reader()
.with(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
.readTree("7976931348623157e309");
assertTrue("Expected DecimalNode, got: "+jsonNode.getClass().getName()+": "+jsonNode, jsonNode.isBigDecimal());
// the following fails with NumberFormatException, because jsonNode is a DoubleNode with a value of POSITIVE_INFINITY
// Assert.assertTrue(jsonNode.decimalValue().compareTo(new BigDecimal("7976931348623157e309")) == 0);
assertEquals(new BigDecimal(value), jsonNode.decimalValue(), );
}
}

0 comments on commit cd3cc18

Please sign in to comment.