From ce753308027e4f5ead82c1353b98594dfb7e1f33 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 16 Mar 2024 21:55:42 +0100 Subject: [PATCH 1/3] add number test --- .../databind/deser/BigDecimalWrapper.java | 17 +++++++++++ .../databind/deser/NumbersDeserTest.java | 29 +++++++++++++++++++ .../databind/deser/TestBigNumbers.java | 15 ---------- 3 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 src/test/java/com/fasterxml/jackson/databind/deser/BigDecimalWrapper.java create mode 100644 src/test/java/com/fasterxml/jackson/databind/deser/NumbersDeserTest.java diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/BigDecimalWrapper.java b/src/test/java/com/fasterxml/jackson/databind/deser/BigDecimalWrapper.java new file mode 100644 index 0000000000..2cbee9da04 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/databind/deser/BigDecimalWrapper.java @@ -0,0 +1,17 @@ +package com.fasterxml.jackson.databind.deser; + +import java.math.BigDecimal; + +final class BigDecimalWrapper { + BigDecimal number; + + public BigDecimalWrapper() {} + + public BigDecimalWrapper(BigDecimal number) { + this.number = number; + } + + public void setNumber(BigDecimal number) { + this.number = number; + } +} diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/NumbersDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/NumbersDeserTest.java new file mode 100644 index 0000000000..eff908ab55 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/databind/deser/NumbersDeserTest.java @@ -0,0 +1,29 @@ +package com.fasterxml.jackson.databind.deser; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class NumbersDeserTest +{ + /* + /********************************************************** + /* Tests + /********************************************************** + */ + + private final ObjectMapper MAPPER = JsonMapper.builder().build(); + + @Test + public void testNumberStartingWithDot() 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/TestBigNumbers.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestBigNumbers.java index 3050e1a011..2eb4c1cf18 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestBigNumbers.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestBigNumbers.java @@ -1,6 +1,5 @@ package com.fasterxml.jackson.databind.deser; -import java.math.BigDecimal; import java.math.BigInteger; import com.fasterxml.jackson.core.JsonFactory; @@ -13,20 +12,6 @@ public class TestBigNumbers extends BaseMapTest { - static class BigDecimalWrapper { - BigDecimal number; - - public BigDecimalWrapper() {} - - public BigDecimalWrapper(BigDecimal number) { - this.number = number; - } - - public void setNumber(BigDecimal number) { - this.number = number; - } - } - static class BigIntegerWrapper { BigInteger number; From 34ffcbe922059516aa4176a88cb795018714ebb1 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 16 Mar 2024 22:20:13 +0100 Subject: [PATCH 2/3] more tests --- .../jackson/databind/deser/NumbersDeserTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/NumbersDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/NumbersDeserTest.java index eff908ab55..994158db23 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/NumbersDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/NumbersDeserTest.java @@ -26,4 +26,20 @@ public void testNumberStartingWithDot() throws Exception assertEquals(new BigDecimal(num), w.number); } + @Test + public void testNumberStartingWithMinusDot() throws Exception + { + String num = "-.555555555555555555555555555555"; + BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class); + assertEquals(new BigDecimal(num), w.number); + } + + @Test + public void testNumberStartingWithPlusDot() throws Exception + { + String num = "+.555555555555555555555555555555"; + BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class); + assertEquals(new BigDecimal(num), w.number); + } + } From f223e0d4be53a7a94ac9d84159524cf5cdcee5d2 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 21 Mar 2024 20:51:37 -0700 Subject: [PATCH 3/3] Minor refactoring --- .../databind/deser/BigDecimalWrapper.java | 17 ----------------- .../jackson/databind/deser/TestBigNumbers.java | 15 +++++---------- .../BigDecimalDeser4435Test.java} | 10 +++++++--- 3 files changed, 12 insertions(+), 30 deletions(-) delete mode 100644 src/test/java/com/fasterxml/jackson/databind/deser/BigDecimalWrapper.java rename src/test/java/com/fasterxml/jackson/databind/deser/{NumbersDeserTest.java => jdk/BigDecimalDeser4435Test.java} (88%) diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/BigDecimalWrapper.java b/src/test/java/com/fasterxml/jackson/databind/deser/BigDecimalWrapper.java deleted file mode 100644 index 2cbee9da04..0000000000 --- a/src/test/java/com/fasterxml/jackson/databind/deser/BigDecimalWrapper.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fasterxml.jackson.databind.deser; - -import java.math.BigDecimal; - -final class BigDecimalWrapper { - BigDecimal number; - - public BigDecimalWrapper() {} - - public BigDecimalWrapper(BigDecimal number) { - this.number = number; - } - - public void setNumber(BigDecimal number) { - this.number = number; - } -} diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestBigNumbers.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestBigNumbers.java index 2eb4c1cf18..78af809158 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestBigNumbers.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestBigNumbers.java @@ -1,5 +1,6 @@ package com.fasterxml.jackson.databind.deser; +import java.math.BigDecimal; import java.math.BigInteger; import com.fasterxml.jackson.core.JsonFactory; @@ -13,17 +14,11 @@ public class TestBigNumbers extends BaseMapTest { static class BigIntegerWrapper { - BigInteger number; - - public BigIntegerWrapper() {} - - public BigIntegerWrapper(BigInteger number) { - this.number = number; - } + public BigInteger number; + } - public void setNumber(BigInteger number) { - this.number = number; - } + static class BigDecimalWrapper { + public BigDecimal number; } /* diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/NumbersDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/BigDecimalDeser4435Test.java similarity index 88% rename from src/test/java/com/fasterxml/jackson/databind/deser/NumbersDeserTest.java rename to src/test/java/com/fasterxml/jackson/databind/deser/jdk/BigDecimalDeser4435Test.java index 994158db23..5ac825a5b7 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/NumbersDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/BigDecimalDeser4435Test.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.databind.deser; +package com.fasterxml.jackson.databind.deser.jdk; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; @@ -8,8 +8,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class NumbersDeserTest +// @since 2.16.3 +public class BigDecimalDeser4435Test { + static class BigDecimalWrapper { + public BigDecimal number; + } + /* /********************************************************** /* Tests @@ -41,5 +46,4 @@ public void testNumberStartingWithPlusDot() throws Exception BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class); assertEquals(new BigDecimal(num), w.number); } - }