-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
I have a string represents a number with 652 decimal places (-11000.00000...). When reading this string to BigDecimal i end up with a wrong number -1.1000E-648. The simple example is found at https://github.com/lnthai2002/jackson-databind-test/blob/db3e060ac38c555b001d91c549e004a19f9a17c7/src/main/java/App.java
Version Information
2.17.1
Reproduction
<-- Any of the following
- Brief code sample/snippet: include here in preformatted/code section
- Longer example stored somewhere else (diff repo, snippet), add a link
- Textual explanation: include here
-->
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import java.math.BigDecimal;
public class App {
public static void main (String [] args) {
JsonNodeFactory f = JsonNodeFactory.withExactBigDecimals(true);
ObjectMapper mapper = new ObjectMapper();
mapper.findAndRegisterModules()
.setNodeFactory(f)
.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true)
.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
String str = "-11000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
try {
BigDecimal num = mapper.readValue(str, BigDecimal.class);
System.out.println(num);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}Expected behavior
should print "-11000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
Additional context
If i switch back to 2.14.1 then i got the correct result