|
1 | 1 | package com.fasterxml.jackson.databind.convert; |
2 | 2 |
|
| 3 | +import java.math.BigDecimal; |
3 | 4 | import java.math.BigInteger; |
4 | 5 | import java.util.*; |
5 | 6 | import java.util.concurrent.atomic.AtomicLong; |
|
12 | 13 | import com.fasterxml.jackson.databind.cfg.CoercionInputShape; |
13 | 14 | import com.fasterxml.jackson.databind.exc.InvalidFormatException; |
14 | 15 | import com.fasterxml.jackson.databind.exc.MismatchedInputException; |
| 16 | +import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
15 | 17 | import com.fasterxml.jackson.databind.type.LogicalType; |
16 | 18 |
|
17 | 19 | import static org.junit.jupiter.api.Assertions.*; |
@@ -79,6 +81,40 @@ public void testLegacyDoubleToIntCoercion() throws Exception |
79 | 81 | assertEquals(95L, biggie.longValue()); |
80 | 82 | } |
81 | 83 |
|
| 84 | + // [databind#5319] |
| 85 | + @Test |
| 86 | + public void testLegacyDoubleToIntCoercionJsonNode() throws Exception |
| 87 | + { |
| 88 | + final ObjectMapper mapperAllow = jsonMapperBuilder() |
| 89 | + .enable(DeserializationFeature.ACCEPT_FLOAT_AS_INT) |
| 90 | + .build(); |
| 91 | + final JsonNodeFactory nodeF = mapperAllow.getNodeFactory(); |
| 92 | + |
| 93 | + // First Integer |
| 94 | + assertEquals(1, |
| 95 | + mapperAllow.treeToValue(nodeF.numberNode(1.25), Integer.class)); |
| 96 | + assertEquals(-2, |
| 97 | + mapperAllow.treeToValue(nodeF.numberNode(-2.5f), Integer.class)); |
| 98 | + assertEquals(3, |
| 99 | + mapperAllow.treeToValue(nodeF.numberNode(BigDecimal.valueOf(3.75)), Integer.class)); |
| 100 | + |
| 101 | + // Second Long |
| 102 | + assertEquals(1L, |
| 103 | + mapperAllow.treeToValue(nodeF.numberNode(1.25), Long.class)); |
| 104 | + assertEquals(-2L, |
| 105 | + mapperAllow.treeToValue(nodeF.numberNode(-2.5f), Long.class)); |
| 106 | + assertEquals(3L, |
| 107 | + mapperAllow.treeToValue(nodeF.numberNode(BigDecimal.valueOf(3.75)), Long.class)); |
| 108 | + |
| 109 | + // Last BigInteger |
| 110 | + assertEquals(BigInteger.valueOf(1L), |
| 111 | + mapperAllow.treeToValue(nodeF.numberNode(1.25), BigInteger.class)); |
| 112 | + assertEquals(BigInteger.valueOf(-2L), |
| 113 | + mapperAllow.treeToValue(nodeF.numberNode(-2.5f), BigInteger.class)); |
| 114 | + assertEquals(BigInteger.valueOf(3L), |
| 115 | + mapperAllow.treeToValue(nodeF.numberNode(BigDecimal.valueOf(3.75)), BigInteger.class)); |
| 116 | + } |
| 117 | + |
82 | 118 | @Test |
83 | 119 | public void testLegacyFailDoubleToInt() throws Exception |
84 | 120 | { |
|
0 commit comments