Skip to content

Document JsonNumber numeric conversion design choices #119

Description

@cursor

Problem

Older revisions of this backport included convenience constructors/factories on the core java.util.json types (notably around JsonNumber) that accepted BigDecimal / BigInteger. After the most recent sync from upstream openjdk/jdk-sandbox those APIs are no longer present.

This leaves users wondering:

  • what happened to the BigDecimal/BigInteger entry points
  • whether their removal was accidental vs. deliberate upstream design
  • how to do lossless numeric handling without the constructor explosion typical of legacy OO APIs

Goal

Document the design choice: JSON numbers are represented primarily as lexical decimal text, with minimal numeric factories (double, long, String) and lossless conversion via toString().

Add runnable examples (and tests) showing:

  • precision loss with double
  • lossless conversion using BigDecimal/BigInteger via toString()
  • how to build JsonNumber from BigDecimal without adding new overloads
  • how lexically-preserving toString() differs from numeric normalization

Deliverables

  • DESIGN_CHOICES.md analysis with examples
  • matching example sources under json-java21/src/main/... and json-java21/src/test/...

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions