question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support `BigInteger` and `BigDecimal` creators in `StdValueInstantiator`

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, May 14, 2020

@verkhovin I have not, so you are welcome to try it!

0reactions
cowtowncodercommented, Jul 23, 2020

Implementation contributed by @upsidedownsmile, just merged.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Security update for jackson-databind, jackson-dataformats ...
READ_ONLY' does not work with "getter-as-setter" 'Collection's + Support 'BigInteger' and 'BigDecimal' creators in 'StdValueInstantiator' + ...
Read more >
BigDecimal and BigInteger in Java - Baeldung
BigDecimal represents an immutable arbitrary-precision signed decimal number. It consists of two parts: Unscaled value – an arbitrary precision ...
Read more >
BigDecimal - Android Developers
Square brackets are used to represent the particular BigInteger and scale pair defining a BigDecimal value; for example [19, 2] is the BigDecimal...
Read more >
Why does Java define BigInteger / BigDecimal values of 10?
BigInteger and BigDecimal are immutable objects. Once instantiated, if you want to do something with it, you create a new object.
Read more >
How to convert BigInteger to BigDecimal? - java - Stack Overflow
I know this reply is late but it will help new users looking for this solution, you can convert BigInteger to BigDecimal by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found