Skip to content

Upgrade to track jdk.incubator.json #145

@simbo1905

Description

@simbo1905

Goal

Upgrade this backport to track the upstream jdk.incubator.json module from the OpenJDK jdk-sandbox json branch.

Background

Upstream has moved the JSON API from java.util.json (in java.base) to jdk.incubator.json (new incubator module). See #144 for full context.

Required Changes

Public API (jdk.sandbox.java.util.json → stays same package)

  • Method renames on JsonValue:
    • bool()asBoolean()
    • toLong()asLong()
    • toDouble()asDouble()
    • string()asString()
    • elements()asList()
    • members()asMap()
    • element(int)get(int)
    • getOrAbsent(String)tryGet(String)
    • valueOrNull()tryValue()
  • New method: asInt() on JsonValue and JsonNumber
  • JsonArray: add get(int) override with bounds-checked error
  • JsonObject: add get(String) and tryGet(String) overrides
  • Remove equals()/hashCode() from all JsonValue subtypes

Exception Changes

  • Rename JsonAssertionExceptionJsonValueException
  • JsonParseException → make final, add non-negative validation for line/pos

Internal Implementation (jdk.sandbox.internal.util.json)

  • JsonNumberImpl: add asInt(), new numInteger LazyConstant, use Math.powExact (Java 25+) or keep polyfill for Java 21
  • JsonObjectImpl: rename members()asMap(), add get()/tryGet() overrides, remove equals/hashCode
  • JsonArrayImpl: rename elements()asList(), add get(int) override, remove equals/hashCode
  • JsonStringImpl: rename string()asString(), remove equals/hashCode
  • JsonBooleanImpl: rename bool()asBoolean(), remove equals/hashCode
  • JsonNullImpl: remove equals/hashCode
  • Utils.java: return JsonValueException instead of JsonAssertionException, remove powExact polyfill if using Java 25+

Infrastructure

  • Update API tracker URLs from java.util.jsonjdk.incubator.json
  • Update RefreshFromUpstream.java to use new path src/jdk.incubator.json/share/classes/jdk/incubator/json/impl/
  • Update transform_upstream.py for new package names
  • Update README.md "Current Status" section

Approach

  1. Fetch upstream sources from json branch at src/jdk.incubator.json/share/classes/
  2. Apply mechanical transformations (package renames, preview annotation removal, Java 21 compatibility)
  3. Preserve local additions (StableValue.java, Utils.java polyfills)
  4. Run full test suite
  5. Update documentation

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions