Skip to content

Commit 5fa1e3e

Browse files
committed
test for issue FasterXML#4917
1 parent 62900a6 commit 5fa1e3e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ static class NestedBigDecimalHolder2784 {
7676
public BigDecimalHolder2784 holder;
7777
}
7878

79+
static class DeserializationIssue4917 {
80+
public DecimalHolder4917 decimalHolder;
81+
public Double number;
82+
}
83+
84+
static class DecimalHolder4917 {
85+
public BigDecimal value;
86+
87+
public DecimalHolder4917(BigDecimal value) {
88+
this.value = value;
89+
}
90+
91+
@JsonCreator
92+
static DecimalHolder4917 of(BigDecimal value) {
93+
return new DecimalHolder4917(value);
94+
}
95+
}
96+
7997
/*
8098
/**********************************************************************
8199
/* Helper classes, serializers/deserializers/resolvers
@@ -362,4 +380,39 @@ public void testBigDecimalUnwrapped() throws Exception
362380
NestedBigDecimalHolder2784 result = mapper.readValue(JSON, NestedBigDecimalHolder2784.class);
363381
assertEquals(new BigDecimal("5.00"), result.holder.value);
364382
}
383+
384+
private final String BIG_DEC_STR;
385+
{
386+
StringBuilder sb = new StringBuilder("-1234.");
387+
// Above 500 chars we get a problem:
388+
for (int i = 520; --i >= 0; ) {
389+
sb.append('0');
390+
}
391+
BIG_DEC_STR = sb.toString();
392+
}
393+
private final BigDecimal BIG_DEC = new BigDecimal(BIG_DEC_STR);
394+
395+
// [databind#4694]: decoded wrong by jackson-core/FDP for over 500 char numbers
396+
@Test
397+
public void bigDecimal4694FromString() throws Exception
398+
{
399+
assertEquals(BIG_DEC, MAPPER.readValue(BIG_DEC_STR, BigDecimal.class));
400+
}
401+
402+
@Test
403+
public void bigDecimal4694FromBytes() throws Exception
404+
{
405+
byte[] b = utf8Bytes(BIG_DEC_STR);
406+
assertEquals(BIG_DEC, MAPPER.readValue(b, 0, b.length, BigDecimal.class));
407+
}
408+
409+
@Test
410+
public void bigDecimal4917() throws Exception
411+
{
412+
DeserializationIssue4917 issue = MAPPER.readValue(
413+
a2q("{'decimalHolder':100.00,'number':50}"),
414+
DeserializationIssue4917.class);
415+
assertEquals(new BigDecimal("100.00"), issue.decimalHolder.value);
416+
}
417+
365418
}

0 commit comments

Comments
 (0)