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

Incorrect deserialization of numerical value #202

Closed
spartanhooah opened this issue Jul 10, 2024 · 4 comments
Closed

Incorrect deserialization of numerical value #202

spartanhooah opened this issue Jul 10, 2024 · 4 comments

Comments

@spartanhooah
Copy link

We're calling an API that returns JSON and has a numeric value of e.g. 10.00. This gets deserialized into a Double of 10.0. IMO this should be deserialized into a BigDecimal instead to maintain the proper precision.

@artamonovkirill
Copy link
Collaborator

Hi, @spartanhooah 👋
Thanks for raising that.
Can you share some examples of how you deserialize the values in your tests?
I've added a few tests for a generic Map and a dedicated Info classes: #203.
Jackson-databind might default to Double when deserializing generic objects (like Map).
I'll dig deeper to verify that and check if that can be configured in the object mapper.

@artamonovkirill
Copy link
Collaborator

artamonovkirill commented Jul 10, 2024

Indeed, USE_BIG_DECIMAL_FOR_FLOATS is one of the Jackson-databind features: https://github.com/FasterXML/jackson-databind/wiki/Deserialization-Features#type-conversions

You can do something like this for your setup:

        def mapper = new ObjectMapper().enable(USE_BIG_DECIMAL_FOR_FLOATS)
        def http = new HttpClient(mapper: mapper)

Please let me know whether you need some extra information or it's OK to close this ticket.

@spartanhooah
Copy link
Author

Ah, I didn't know we could pass an ObjectMapper to the HttpClient. That sounds like it'll work perfectly. Let me test it out.

@spartanhooah
Copy link
Author

That does the trick. Thank you.

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

2 participants