Skip to content

Incorrect deserialization for BigDecimal numbers #1770

@cristian-mocanu-mob

Description

@cristian-mocanu-mob

If the number in JSON cannot be represented as Double and DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS is enabled, big numbers are returned as Infinity.

The test below should pass:

        final ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);

        final JsonNode jsonNode = objectMapper.readTree("7976931348623157e309");
        Assert.assertTrue(jsonNode instanceof NumericNode);

        // the following fails with NumberFormatException, because jsonNode is a DoubleNode with a value of POSITIVE_INFINITY
        Assert.assertTrue(jsonNode.decimalValue().compareTo(new BigDecimal("7976931348623157e309")) == 0);

The problem is reproducible in the latest released version, 2.9.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    has-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions