FasterXML / jackson-databind

General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Apache License 2.0
3.53k stars 1.38k forks source link

Consider adding `JsonNodeFeature` to allow overriding `DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS` #4801

Open cowtowncoder opened 3 days ago

cowtowncoder commented 3 days ago

Describe your Issue

Due to eager binding of number type when reading JsonNode -- basically, decision must be made between reading:

  1. Slightly faster, but potentially lossy Double vs
  2. Bit slower but unlimited range/precision BigDecimal

(to get either DoubleNode or BigDecimalNode)

there are cases where common buffering use cases expose unexpected precision loss -- particular since by default Double is used. See, for example:

https://github.com/FasterXML/jackson-modules-java8/issues/326

This behavior can be changed via DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, but that is global setting. Instead, it would perhaps make sense to add a JsonNodeFeature which would only affect JsonNode reading, but would have precedence over DeserializationFeature.

I haven't thought this fully through wrt implementation but this seems like potentially useful thing to have.