1 package com.fasterxml.jackson.failing; 2 3 import com.fasterxml.jackson.databind.*; 4 5 /** 6 * Basic tests for {@link JsonNode} implementations that 7 * contain numeric values. 8 */ 9 public class NumberNodes1770Test extends BaseMapTest 10 { 11 private final ObjectMapper MAPPER = newJsonMapper(); 12 13 // For to [databind#1770] (broken due to fix for #1028): `JsonNodeDeserializer` 14 // would coerce ok but does `parser.isNaN()` check which ends up parsing 15 // as Double, gets `POSITIVE_INFINITY` and returns `true`: this results in 16 // `DoubleNode` being used even tho `BigDecimal` could fit the number. testBigDecimalCoercion()17 public void testBigDecimalCoercion() throws Exception 18 { 19 final JsonNode jsonNode = MAPPER.reader() 20 .with(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS) 21 .readTree("7976931348623157e309"); 22 assertTrue("Expected DecimalNode, got: "+jsonNode.getClass().getName()+": "+jsonNode, jsonNode.isBigDecimal()); 23 // the following fails with NumberFormatException, because jsonNode is a DoubleNode with a value of POSITIVE_INFINITY 24 // Assert.assertTrue(jsonNode.decimalValue().compareTo(new BigDecimal("7976931348623157e309")) == 0); 25 } 26 } 27