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
JsonAssertionException → JsonValueException
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.json → jdk.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
- Fetch upstream sources from
json branch at src/jdk.incubator.json/share/classes/
- Apply mechanical transformations (package renames, preview annotation removal, Java 21 compatibility)
- Preserve local additions (
StableValue.java, Utils.java polyfills)
- Run full test suite
- Update documentation
Goal
Upgrade this backport to track the upstream
jdk.incubator.jsonmodule from the OpenJDK jdk-sandboxjsonbranch.Background
Upstream has moved the JSON API from
java.util.json(injava.base) tojdk.incubator.json(new incubator module). See #144 for full context.Required Changes
Public API (
jdk.sandbox.java.util.json→ stays same package)JsonValue:bool()→asBoolean()toLong()→asLong()toDouble()→asDouble()string()→asString()elements()→asList()members()→asMap()element(int)→get(int)getOrAbsent(String)→tryGet(String)valueOrNull()→tryValue()asInt()onJsonValueandJsonNumberget(int)override with bounds-checked errorget(String)andtryGet(String)overridesequals()/hashCode()from all JsonValue subtypesException Changes
JsonAssertionException→JsonValueExceptionJsonParseException→ makefinal, add non-negative validation for line/posInternal Implementation (
jdk.sandbox.internal.util.json)JsonNumberImpl: addasInt(), newnumIntegerLazyConstant, useMath.powExact(Java 25+) or keep polyfill for Java 21JsonObjectImpl: renamemembers()→asMap(), addget()/tryGet()overrides, remove equals/hashCodeJsonArrayImpl: renameelements()→asList(), addget(int)override, remove equals/hashCodeJsonStringImpl: renamestring()→asString(), remove equals/hashCodeJsonBooleanImpl: renamebool()→asBoolean(), remove equals/hashCodeJsonNullImpl: remove equals/hashCodeUtils.java: returnJsonValueExceptioninstead ofJsonAssertionException, removepowExactpolyfill if using Java 25+Infrastructure
java.util.json→jdk.incubator.jsonRefreshFromUpstream.javato use new pathsrc/jdk.incubator.json/share/classes/jdk/incubator/json/impl/transform_upstream.pyfor new package namesApproach
jsonbranch atsrc/jdk.incubator.json/share/classes/StableValue.java,Utils.javapolyfills)