Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in 2.15: parsing double value returns BigDecimal instead of Double #39

Closed
dlipin opened this issue Sep 20, 2023 · 3 comments
Closed

Comments

@dlipin
Copy link

dlipin commented Sep 20, 2023

I'm filing this issue as the result of conversation in pull request:
#32

Here is the test:


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;

public class JsonDoubleTest {

    @Test
    public void testDoubleParsing() throws Exception {
        ObjectMapper objectMapper = new ObjectMapper().registerModule(new JsonOrgModule());
        JSONObject jsonObject = objectMapper.readValue("{\"value\": 0.5 }", JSONObject.class);
        Assert.assertEquals("java.lang.Double", jsonObject.get("value").getClass().getCanonicalName());
    }
}

When I run it with Jackson 2.13.4 then it passes. When I run it with Jackson 2.15.0, it fails with error:

org.junit.ComparisonFailure: 
Expected :java.lang.Double
Actual   :java.math.BigDecimal
@dlipin dlipin changed the title Regression in 2.15: Regression in 2.15: parsing double value returns BigInteger instead of Double Sep 20, 2023
@dlipin dlipin changed the title Regression in 2.15: parsing double value returns BigInteger instead of Double Regression in 2.15: parsing double value returns BigDecimal instead of Double Sep 20, 2023
@cowtowncoder
Copy link
Member

Ok so the question is: is the new behavior erroneous? Yes, it is a change and in hindsight unfortunate. But given there is new behavior for 2.15 I am not sure reverting change is the right thing to do.

Also see #38 for more discussion.

One possible way forward would be to support DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, but problem there is that it is disabled by default so using it to determine behavior would mean reverting behavior.
Yet another possibility would be module-specific Feature.

@pjfanning WDYT?

@pjfanning
Copy link
Member

pjfanning commented Sep 26, 2023

This is very easily worked around - see #32 (comment)

The old behaviour had a bug. It did not handle big numbers properly. Users who want doubles can still get doubles by using the API to ask for a Double. Examples in https://github.com/FasterXML/jackson-datatypes-misc/pull/38/files

The code in #38 should work in older versions of Jackson too (see #40)

@cowtowncoder
Copy link
Member

Ok I think I'll close this then, after tests were added to document the new behavior.

@cowtowncoder cowtowncoder closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants