You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "mohitjoshi-hey (via GitHub)" <gi...@apache.org> on 2026/10/13 16:15:42 UTC
[PR] fix (java): preserve precision for untyped JSON numbers [fory]
mohitjoshi-hey opened a new pull request, #4178:
URL: https://github.com/apache/fory/pull/4178
## Why?
When JSON is read into `Object.class`, decimal and exponent-form number literals were converted to `Double`. This caused precision loss for literals that could not be represented exactly as a `double`, for example:
- `1.234567890123456789012345678901234567890`
- `1e400`
- `0.1000000000000000055511151231257827021181583404541015625`
This is problematic for schemaless applications that first read JSON without a type and resolve the type later.
## What does this PR do?
- Preserves untyped decimal and exponent-form JSON numbers as `BigDecimal`.
- Keeps the existing integer behavior:
- Values within the `Long` range remain `Long`.
- Larger integer values remain `BigInteger`.
- Preserves existing behavior for explicitly typed floating-point values.
- Adds the optimized exact-number path to the UTF-8 JSON reader.
- Adds regression coverage for:
- High-precision decimal literals.
- UTF-8 byte input.
- Large exponent values such as `1e400`.
- Large integer values.
## Related issues
Fixes #4170
## Validation
Command:
```text
mvn -pl fory-json -Dtest=JsonContainerTest#preserveNaturalDecimalPrecision test
```
Result:
<img width="1521" height="392" alt="image" src="https://github.com/user-attachments/assets/2cb0e45a-f8c5-4b40-9e10-809d4c6177ad" />
## AI Contribution Checklist
- [x] Substantial AI assistance was used in this PR: `yes`
- [x] If `yes`, I included a completed [AI Contribution Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs) in this PR description and the required `AI Usage Disclosure`.
- [ ] If `yes`, my PR description includes the required `ai_review` summary and screenshot evidence or equivalent persisted links of the final clean AI review results from both fresh reviewers described in `AI_POLICY.md`, the Fory-guided reviewer and the independent general reviewer, on the current PR diff or current HEAD after the latest code changes.
### AI Usage Disclosure
```text
AI Usage Disclosure
- substantial_ai_assistance: yes
- scope: design drafting, code drafting, tests, and review
- affected_files_or_subsystems: Java Fory JSON reader, UTF-8 JSON reader, scalar codecs, and JSON container tests
- ai_review: Pending completion of the required fresh Fory-guided and independent general reviews.
- ai_review_artifacts: Pending. Add the final clean-review screenshots or persistent links from both reviewers before submission.
- human_verification: Ran:
`mvn -pl fory-json -Dtest=JsonContainerTest#preserveNaturalDecimalPrecision test`
Result: Tests run: 2, Failures: 0, Errors: 0, Skipped: 0; BUILD SUCCESS.
Note: Verify the selected test method and investigate any unrelated suite failures before making broader test-suite claims.
- performance_verification: No benchmark was run. The change is intended as a correctness fix for untyped JSON number materialization. Verify performance implications before making definitive performance claims.
- provenance_license_confirmation: Confirm that all contributions are compatible with the Apache-2.0 license and that no incompatible third-party code was introduced.
```
### Completed AI Review Checklist
- [x] Substantial AI assistance was used in this PR: `yes`
- [x] If `yes`, I included the standardized `AI Usage Disclosure` block above.
- [ ] If `yes`, I can explain and defend all important changes without AI help.
- [ ] If `yes`, I reviewed AI-assisted code changes line by line before submission.
- [ ] If `yes`, I completed line-by-line self-review first and fixed issues before requesting AI review.
- [ ] If `yes`, I ran two fresh AI review agents on the current PR diff or current HEAD after the latest code changes: one Fory-guided reviewer and one independent general reviewer.
- [ ] If `yes`, I addressed all actionable AI review comments and repeated the review loop until both AI reviewers reported no further actionable comments.
- [ ] If `yes`, I attached screenshot evidence or equivalent persisted links of the final clean-review results from both reviewers in this PR body.
- [x] If `yes`, I ran a focused test command and recorded its result above.
- [x] If `yes`, I added regression tests for the reported issue.
- [ ] If `yes`, I validated protocol and performance impacts; no binary protocol change was introduced.
- [ ] If `yes`, I verified licensing and provenance compliance.
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
The untyped JSON result for decimal and exponent-form numbers changes from `Double` to `BigDecimal` so that the original number literal is preserved. Explicitly typed numeric reads are intended to remain unchanged.
## Benchmark
No benchmark was run. This is intended as a correctness fix for untyped JSON number materialization. Benchmarking may be needed if review identifies a meaningful performance impact.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] fix(java): preserve precision for untyped JSON numbers [fory]
Posted by "mohitjoshi-hey (via GitHub)" <gi...@apache.org>.
mohitjoshi-hey commented on PR #4178:
URL: https://github.com/apache/fory/pull/4178#issuecomment-6187250632
Hey, @chaokunyang! Can you please review my PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org