Skip to content

Commit 7c336bf

Browse files
authored
Mark #4694 as fixed (actual fix via jackson-core) (#4700)
1 parent b9d5e42 commit 7c336bf

File tree

3 files changed

+28
-40
lines changed

3 files changed

+28
-40
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Project: jackson-databind
7575
(reported by Mathijs V)
7676
#4688: Should allow deserializing with no-arg `@JsonCreator(mode = DELEGATING)`
7777
(contributed by Carter K)
78+
#4694: Deserializing `BigDecimal` with large number of decimals result in incorrect value
79+
(reported by @lnthai2002)
7880
7981
2.17.2 (05-Jul-2024)
8082

src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKNumberDeserTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,30 @@ public void testBigDecimalUnwrapped() throws Exception
386386
NestedBigDecimalHolder2784 result = mapper.readValue(JSON, NestedBigDecimalHolder2784.class);
387387
assertEquals(new BigDecimal("5.00"), result.holder.value);
388388
}
389+
390+
private final String BIG_DEC_STR;
391+
{
392+
StringBuilder sb = new StringBuilder("-1234.");
393+
// Above 500 chars we get a problem:
394+
for (int i = 520; --i >= 0; ) {
395+
sb.append('0');
396+
}
397+
BIG_DEC_STR = sb.toString();
398+
}
399+
private final BigDecimal BIG_DEC = new BigDecimal(BIG_DEC_STR);
400+
401+
// [databind#4694]: decoded wrong by jackson-core/FDP for over 500 char numbers
402+
@Test
403+
public void bigDecimal4694FromString() throws Exception
404+
{
405+
assertEquals(BIG_DEC, MAPPER.readValue(BIG_DEC_STR, BigDecimal.class));
406+
}
407+
408+
@Test
409+
public void bigDecimal4694FromBytes() throws Exception
410+
{
411+
byte[] b = utf8Bytes(BIG_DEC_STR);
412+
assertEquals(BIG_DEC, MAPPER.readValue(b, 0, b.length, BigDecimal.class));
413+
}
414+
389415
}

src/test/java/com/fasterxml/jackson/failing/BigDecimalParsing4694Test.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)