Support `BigInteger` and `BigDecimal` creators in `StdValueInstantiator`
See original GitHub issueCurrently 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:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@verkhovin I have not, so you are welcome to try it!
Implementation contributed by @upsidedownsmile, just merged.