-
Notifications
You must be signed in to change notification settings - Fork 33
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
Deserializes "null" to "0.0" for java.lang.Double
(wrapper)
#78
Comments
Found out that big-B Booleans have the same problem. Most likely Integer, etc. as well. |
Thank you for reporting this, it does sound like a bug. |
I'm actually on 2.12.1, sorry I didn't know 2.12.2 was out. I found a workaround; add a reader/writer provider that provides this object when a reader for Double.class is needed:
But it seems it would be best to make this workaround unnecessary, to just preserve nulls. (I have verified that yes, Integer, Boolean, Float, and Character, all have this problem, all can be fixed by the same workaround technique. I guess I have some of complex beans.) |
Yes, I agree that nulls should be preserved for wrapper types by default (and if there was a coercion, that'd be separate setting). But I now realize that there's definitely the backwards-compatibility angle to consider... meaning that the change in behavior may need to wait until 2.13.0 (patch releases should minimize regression likelihood for users, and this is one of those possibly "bug or feature?" cases). |
Since I have my workaround in place I'm OK with waiting until 2.13. Thanks for listening. I'm always in favor of strictness in serialization/deserialization; if I have a little-d double, and get a null, I'd rather see an exception thrown (since this means my schema doesn't match the data) than see it quietly turned into 0.0. But I know other people prefer the "do whatever it takes to shove the data into the bean" approach. |
@bill-phast exactly. There are two quite different philosophies... and some people find it difficult to believe there is the "other side", too. :) In this case behavior is definitely not intentional but oversight. But over time even unintended behavior becomes sort of de fact specification. BTW, if you would like to get exception for "null for primitives" case, I'd be happy to add that as a |
Thanks! Yes I can see the other side of it. I may write that pull request, it doesn't look like it would be too hard. |
Hmmh. On this particular problem, I realized that this is bit trickier because deserializer side does not currently track primitive/tracker difference: internally there are numeric constants like |
I looked at stricter handling of values, and ran into the same problem - want to fail on null with an "int" and pass the null back on an "Integer" but that doesn't work since at the deserializer level we can't tell them apart. It looks like you've started work on 2.13, I'll wait until that appears then return to it. |
2.13 branch is open, so PRs are possible against. Unfortunately I don't think I will have time to work on this problem in near future. I think that to make this change, new type constants would be needed for standard deserializers (one for each primitive/wrapper case), and then matching changes to |
…ulls Fix part of #78: handle `java.lang.Boolean` separate from primitive `boolean`
java.lang.Double
(wrapper)
…ulls Fixes #78: add wrapper types for most numbers
Finally got back and implemented for |
I'm afraid this is still an issue with 2.17.1. A difference in my case is that the field's type is |
@orolhawion No Kotlin types are supported by jackson-jr, and no specific plans to add support. |
When a bean has a big-d Double, and the value is null, it gets decoded as 0.0 instead. The two are not equivalent.
This code shows the problem:
Output:
The fourth JSON object should be deserialized the same as the third.
The text was updated successfully, but these errors were encountered: