Skip to content

Support BigInteger and BigDecimal creators in StdValueInstantiator #2215

@eatdrinksleepcode

Description

@eatdrinksleepcode

Currently using 2.9.6; have searched and don't see any planned changes in this area.

Basically, I would like this test to pass by default:

private static class BigDecimalWrapper {
    public final BigDecimal value;
    public BigDecimalWrapper(BigDecimal value) { this.value = value; }
}
@Test
public void createFromBigDecimal() throws IOException {
    assertThat(new ObjectMapper().readValue("42.5", BigDecimalWrapper.class).value, is(new BigDecimal("42.5")));
}

the same way that this one does:

private static class DoubleWrapper {
    public final Double value;
    public DoubleWrapper(Double value) { this.value = value; }
}
@Test
public void createFromDouble() throws IOException {
    assertThat(new ObjectMapper().readValue("42.5", DoubleWrapper.class).value, is(new Double("42.5")));
}

Currently, StdValueInstantiator does not support BigDecimal (or BigInteger) at all. I would like to add support for BigDecimal creators to createFromDouble, createFromLong, and createFromInt (and BigInteger creators to createFromLong and createFromInt) in StdValueInstantiator as widening conversions, the same way that createFromInt supports using long creators as a widening conversion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions