Skip to content

Commit

Permalink
test for issue FasterXML#4917
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Jan 22, 2025
1 parent 6660ca1 commit c3f7561
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ static class NestedBigDecimalHolder2784 {
public BigDecimalHolder2784 holder;
}

static class DeserializationIssue4917 {
public DecimalHolder4917 decimalHolder;
public Double number;
}

static class DecimalHolder4917 {
public BigDecimal value;

public DecimalHolder4917(BigDecimal value) {
this.value = value;
}

@JsonCreator
static DecimalHolder4917 of(BigDecimal value) {
return new DecimalHolder4917(value);
}
}

/*
/**********************************************************************
/* Helper classes, serializers/deserializers/resolvers
Expand Down Expand Up @@ -362,4 +380,39 @@ public void testBigDecimalUnwrapped() throws Exception
NestedBigDecimalHolder2784 result = mapper.readValue(JSON, NestedBigDecimalHolder2784.class);
assertEquals(new BigDecimal("5.00"), result.holder.value);
}

private final String BIG_DEC_STR;
{
StringBuilder sb = new StringBuilder("-1234.");
// Above 500 chars we get a problem:
for (int i = 520; --i >= 0; ) {
sb.append('0');
}
BIG_DEC_STR = sb.toString();
}
private final BigDecimal BIG_DEC = new BigDecimal(BIG_DEC_STR);

// [databind#4694]: decoded wrong by jackson-core/FDP for over 500 char numbers
@Test
public void bigDecimal4694FromString() throws Exception
{
assertEquals(BIG_DEC, MAPPER.readValue(BIG_DEC_STR, BigDecimal.class));
}

@Test
public void bigDecimal4694FromBytes() throws Exception
{
byte[] b = utf8Bytes(BIG_DEC_STR);
assertEquals(BIG_DEC, MAPPER.readValue(b, 0, b.length, BigDecimal.class));
}

@Test
public void bigDecimal4917() throws Exception
{
DeserializationIssue4917 issue = MAPPER.readValue(
a2q("{'decimalHolder':100.00,'number':50}"),
DeserializationIssue4917.class);
assertEquals(new BigDecimal("100.00"), issue.decimalHolder.value);
}

}

0 comments on commit c3f7561

Please sign in to comment.