Skip to content

Commit

Permalink
Add failing test for #2785
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 8, 2020
1 parent 0ea66a0 commit a8182ea
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.*;

// Tests for
//
// [databind#2644]
// [databind#2785]
public class JDKNumberDeser2644Test extends BaseMapTest
{
// [databind#2644]
Expand Down Expand Up @@ -35,6 +40,16 @@ public void setVal(BigDecimal val) {
}
}

// [databind#2785]
static class BigDecimalHolder2785 {
public BigDecimal value;
}

static class NestedBigDecimalHolder2785 {
@JsonUnwrapped
public BigDecimalHolder2785 holder;
}

// [databind#2644]
public void testBigDecimalSubtypes() throws Exception
{
Expand All @@ -50,7 +65,22 @@ public void testBigDecimalSubtypes() throws Exception
);

assertEquals(new BigDecimal("9999999999999999.99"), root.node.getVal());

}

// [databind#2785]

public void testBigDecimalUnwrapped() throws Exception
{
final ObjectMapper mapper = newJsonMapper();
// mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
final String JSON = "{\"value\": 5.00}";

// first simple working case:
BigDecimalHolder2785 holder = mapper.readValue(JSON, BigDecimalHolder2785.class);
assertEquals(new BigDecimal("5.00"), holder.value);

// and then one that doesn't
NestedBigDecimalHolder2785 result = mapper.readValue(JSON, NestedBigDecimalHolder2785.class);
assertEquals(new BigDecimal("5.00"), result.holder.value);
}
}

0 comments on commit a8182ea

Please sign in to comment.