-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[java] fix parsing numeric values with exponents in JSON #16988
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
[java] fix parsing numeric values with exponents in JSON #16988
Conversation
1. `newInput("42e-1").nextNumber()` returned 4 (expected: 4.2);
2. `new Json().toType("42e-1", Double.class)` returned 4.0 (expected: 4.2)
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
…ing too long numbers
|
@asolntsev i think we are overengineering here. I would suggest to continue with the original PR and focus to the root issue. |
That's my point: I tried to create a simpler solution :) The case it solves is the following:
|
|
The type guess issue does also happen in other areas. So i will create a second PR later to pull all guesses to one point. After this we can fix the issue, now it is just at one point so we have a different behavior inside the Json processing. |
|
I think we should really check each single input character: |
|
overseeded by #16961 |
User description
newInput("42e-1").nextNumber()returned 4 (expected: 4.2);new Json().toType("42e-1", Double.class)returned 4.0 (expected: 4.2)🔗 Related Issues
This is an alternative implementation for problem #16961
💥 What does this PR do?
Fixes parsing numeric values with exponents in JSON.
newInput("42e-1").nextNumber()new Json().toType("42e-1", Double.class)🔄 Types of changes
@joerg1985 What do you think?
PR Type
Bug fix
Description
Fixes JSON number parsing with scientific notation (exponents)
Detects fractional results from exponent calculations
Returns appropriate type (long vs double) based on result
Adds comprehensive test coverage for exponent scenarios
Diagram Walkthrough
File Walkthrough
JsonInput.java
Add exponent result detection to number parsingjava/src/org/openqa/selenium/json/JsonInput.java
nextNumber()to detect fractional results from exponentcalculations
number.stripTrailingZeros().scale() > 0to identifydecimals
doubleValue()for fractional results,longValue()for integersJsonInputTest.java
Add exponent parsing tests to JsonInputTestjava/test/org/openqa/selenium/json/JsonInputTest.java
420L)
JsonTest.java
Add exponent conversion tests to JsonTestjava/test/org/openqa/selenium/json/JsonTest.java
Json.toType()with various exponent formatsvalues