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

Null Double parsed as NaN #192

Open
ertasso opened this issue Jul 10, 2018 · 1 comment
Open

Null Double parsed as NaN #192

ertasso opened this issue Jul 10, 2018 · 1 comment

Comments

@ertasso
Copy link

ertasso commented Jul 10, 2018

I think there is some ambiguity in how the null numeric values are parsed. Or, at least, it would be nice to have a somehow configurable behaviour.

Here is the issue.
I have this bean:

@PropertyDefinition(validate = "notNull")
private final Double number;

When I parse the following jsons (which should represent the same content) I get two different results

{"number":null} --> number=Double.NaN
{} --> number=null --> IllegalArgumentException("Argument number must not be null")

I expected to get the exception in both cases.
What do you think?

I noticed that AbstractJsonReader leniently accepts null as NaN. Would it be possible to change this in your opinion?

@jodastephen
Copy link
Member

The normal way to write a primitive value is:

@PropertyDefinition
private final double number;

JSON does not support NaN, so the parsing of null is intended to provide a backdoor way of passing NaN from something that strictly rejects NaN.

I'd be reluctant to change the behaviour as someone may be relying on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants