• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.node;
2 
3 import java.math.BigDecimal;
4 
5 import com.fasterxml.jackson.databind.*;
6 
7 public class NotANumberConversionTest extends BaseMapTest
8 {
9     private final ObjectMapper m = new ObjectMapper();
10     {
11         m.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
12     }
13 
testBigDecimalWithNaN()14     public void testBigDecimalWithNaN() throws Exception
15     {
16         JsonNode tree = m.valueToTree(new DoubleWrapper(Double.NaN));
17         assertNotNull(tree);
18         String json = m.writeValueAsString(tree);
19         assertNotNull(json);
20 
21         tree = m.valueToTree(new DoubleWrapper(Double.NEGATIVE_INFINITY));
22         assertNotNull(tree);
23         json = m.writeValueAsString(tree);
24         assertNotNull(json);
25 
26         tree = m.valueToTree(new DoubleWrapper(Double.POSITIVE_INFINITY));
27         assertNotNull(tree);
28         json = m.writeValueAsString(tree);
29         assertNotNull(json);
30     }
31 
32     // for [databind#1315]: no accidental coercion to DoubleNode
testBigDecimalWithoutNaN()33     public void testBigDecimalWithoutNaN() throws Exception
34     {
35         BigDecimal input = new BigDecimal(Double.MIN_VALUE).divide(new BigDecimal(10L));
36         JsonNode tree = m.readTree(input.toString());
37         assertTrue(tree.isBigDecimal());
38         BigDecimal output = tree.decimalValue();
39         assertEquals(input, output);
40     }
41 }
42