From 6224569a09e2aae86943c5dd8f586fa40c6ad411 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sat, 23 Mar 2024 11:58:56 -0700 Subject: [PATCH] Fix #4435 (or rather, mark as fixed; fix via jackson-core) (#4446) --- release-notes/VERSION-2.x | 8 ++- .../deser/jdk/BigDecimalDeser4435Test.java | 57 ------------------- .../deser/{ => jdk}/BigNumbersDeserTest.java | 38 +++++++++++-- 3 files changed, 38 insertions(+), 65 deletions(-) delete mode 100644 src/test/java/com/fasterxml/jackson/databind/deser/jdk/BigDecimalDeser4435Test.java rename src/test/java/com/fasterxml/jackson/databind/deser/{ => jdk}/BigNumbersDeserTest.java (74%) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index e7fce3a464..6c56cd42e1 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -12,7 +12,11 @@ Project: jackson-databind #4428: `ByteBuddy` scope went beyond `test` in version 2.17.0 (reported by Miguel M-R) - (fix contributed by Joo-Hyuk K) + (fix by Joo-Hyuk K) +#4435: Cannot deserialize value of type `java.math.BigDecimal` from + String ".05": not a valid representation + (reported by @EAlf91) + (fix by @pjfanning) 2.17.0 (12-Mar-2024) @@ -99,7 +103,7 @@ Project: jackson-databind #1770: Incorrect deserialization for `BigDecimal` numbers (reported by @cristian-mocanu-mob) - (fix contributed by @pjfanning) + (fix by @pjfanning) #2502: Add a way to configure caches Jackson uses (contributed by Joo-Hyuk K) #2787: Mix-ins do not work for `Enum`s diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/jdk/BigDecimalDeser4435Test.java b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/BigDecimalDeser4435Test.java deleted file mode 100644 index 76f3443548..0000000000 --- a/src/test/java/com/fasterxml/jackson/databind/deser/jdk/BigDecimalDeser4435Test.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.fasterxml.jackson.databind.deser.jdk; - -import java.math.BigDecimal; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.json.JsonMapper; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -// @since 2.16.3 -public class BigDecimalDeser4435Test -{ - static class BigDecimalWrapper { - public BigDecimal number; - } - - /* - /********************************************************** - /* Tests - /********************************************************** - */ - - private final ObjectMapper MAPPER = JsonMapper.builder().build(); - - // Disabled until [databind#4435 fixed] - @Disabled - @Test - public void testNumberStartingWithDot() throws Exception - { - String num = ".555555555555555555555555555555"; - BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class); - assertEquals(new BigDecimal(num), w.number); - } - - // Disabled until [databind#4435 fixed] - @Disabled - @Test - public void testNumberStartingWithMinusDot() throws Exception - { - String num = "-.555555555555555555555555555555"; - BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class); - assertEquals(new BigDecimal(num), w.number); - } - - // Disabled until [databind#4435 fixed] - @Disabled - @Test - public void testNumberStartingWithPlusDot() throws Exception - { - String num = "+.555555555555555555555555555555"; - BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class); - assertEquals(new BigDecimal(num), w.number); - } -} diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/BigNumbersDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/BigNumbersDeserTest.java similarity index 74% rename from src/test/java/com/fasterxml/jackson/databind/deser/BigNumbersDeserTest.java rename to src/test/java/com/fasterxml/jackson/databind/deser/jdk/BigNumbersDeserTest.java index ee945235c4..6ff70ba031 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/BigNumbersDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/BigNumbersDeserTest.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.databind.deser; +package com.fasterxml.jackson.databind.deser.jdk; import java.math.BigDecimal; import java.math.BigInteger; @@ -11,15 +11,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; -import com.fasterxml.jackson.databind.testutil.DatabindTestUtil.DoubleWrapper; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; -import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; -import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.verifyException; - public class BigNumbersDeserTest + extends DatabindTestUtil { static class BigIntegerWrapper { public BigInteger number; @@ -31,7 +30,7 @@ static class BigDecimalWrapper { /* /********************************************************** - /* Tests + /* Test methods /********************************************************** */ @@ -103,6 +102,33 @@ public void testBigIntegerUnlimited() throws Exception assertNotNull(bdw); } + // [databind#4435] + @Test + public void testNumberStartingWithDot() throws Exception + { + String num = ".555555555555555555555555555555"; + BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class); + assertEquals(new BigDecimal(num), w.number); + } + + // [databind#4435] + @Test + public void testNumberStartingWithMinusDot() throws Exception + { + String num = "-.555555555555555555555555555555"; + BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class); + assertEquals(new BigDecimal(num), w.number); + } + + // [databind#4435] + @Test + public void testNumberStartingWithPlusDot() throws Exception + { + String num = "+.555555555555555555555555555555"; + BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class); + assertEquals(new BigDecimal(num), w.number); + } + private String generateJson(final String fieldName) { final int len = 1200; final StringBuilder sb = new StringBuilder();