Skip to content

Commit

Permalink
issue-1770 - big number not returned as DecimalNode
Browse files Browse the repository at this point in the history
Update NumberNodes1770Test.java

Update NumberNodes1770Test.java
  • Loading branch information
pjfanning committed Nov 7, 2023
1 parent 604cdbd commit 1fcc82a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 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");
.readTree(value);
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 1fcc82a

Please sign in to comment.