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

JsonWriter#value(java.lang.Number) can be lenient, but JsonWriter#value(double) can't, #1090

Closed
Miha-x64 opened this issue May 30, 2017 · 1 comment

Comments

@Miha-x64
Copy link
Contributor

In lenient mode, JsonWriter#value(java.lang.Number) can write pseudo-numeric values like NaN, Infinity, -Infinity:

    if (!lenient
        && (string.equals("-Infinity") || string.equals("Infinity") || string.equals("NaN"))) {
      throw new IllegalArgumentException("Numeric values must be finite, but was " + value);
    }

But JsonWriter#value(double) behaves in different way:

    if (Double.isNaN(value) || Double.isInfinite(value)) {
      throw new IllegalArgumentException("Numeric values must be finite, but was " + value);
    }

So, while working with streaming, it's impossible to write semi-numeric value without boxing a double (e. g. out.value((Number) Double.valueOf(Double.NaN))).

I think, this should be possible, because boxing gives worse performance.

@inder123
Copy link
Collaborator

Can you create a Pull Request with a JUnit test that fails? Even better would be a fix that makes the test pass. Thanks.

inder123 pushed a commit that referenced this issue May 31, 2017
…e(Number) does (#1093)

* Added test which shows that lenient JsonWriter fails writing infinite primitive doubles, but does not fail writing boxed doubles, as stated in #1090.

* Fixed JsonWriter#value(double) to write infinite and NaN values when lenient, as JsonWriter#value(Number) does. (fixes #1090)
sebasjm pushed a commit to sebasjm/gson that referenced this issue Mar 11, 2018
…e(Number) does (google#1093)

* Added test which shows that lenient JsonWriter fails writing infinite primitive doubles, but does not fail writing boxed doubles, as stated in google#1090.

* Fixed JsonWriter#value(double) to write infinite and NaN values when lenient, as JsonWriter#value(Number) does. (fixes google#1090)
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