Skip to content

Commit 8dec57f

Browse files
authored
Implement JSON Type Definition (JTD) RFC 8927 validator with full compliance (Closes #85) (#87)
This PR #87 deletes the json-java21-schema module and adds a complete implementation of JSON Type Definition (JTD) RFC 8927 validator as requested in issue #85. Here's what was accomplished: 🎯 What Was Actually Built (Issue #85) Complete JTD RFC 8927 validator, replacing the deleted JSON Schema module All 8 schema forms implemented: Empty, Ref, Type, Enum, Elements, Properties, Values, Discriminator 423 tests passing: 58 unit + 365 official JTD Test Suite integration tests Full RFC compliance: Leap seconds, strict properties, ref resolution, discriminator exemption Production-ready architecture: Stack-based validation, immutable records, lazy resolution 📊 Scope of Work 15 commits of intensive development 89 files changed: 4,527 insertions, 10,135 deletions Complete module transformation: json-java21-schema → json-java21-jtd Comprehensive documentation: README.md, ARCHITECTURE.md, API docs
1 parent 6978b7b commit 8dec57f

File tree

89 files changed

+4535
-10135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+4535
-10135
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ jobs:
3939
for k in totals: totals[k]+=int(r.get(k,'0'))
4040
except Exception:
4141
pass
42-
exp_tests=4436
43-
exp_skipped=1692
42+
exp_tests=460
43+
exp_skipped=0
4444
if totals['tests']!=exp_tests or totals['skipped']!=exp_skipped:
4545
print(f"Unexpected test totals: {totals} != expected tests={exp_tests}, skipped={exp_skipped}")
4646
sys.exit(1)

AGENTS.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ LOG.fine(() -> "PERFORMANCE WARNING: Validation stack processing " + count + ...
8585
```
8686

8787
### Additional Guidance
88-
- Logging rules apply globally, including the JSON Schema validator. The helper superclass ensures JUL configuration remains compatible with `$(command -v mvnd || command -v mvn || command -v ./mvnw)`.
88+
- Logging rules apply globally. The helper superclass ensures JUL configuration remains compatible with `$(command -v mvnd || command -v mvn || command -v ./mvnw)`.
8989

9090
## JSON Compatibility Suite
9191
```bash
@@ -103,7 +103,7 @@ mvn exec:java -pl json-compatibility-suite -Dexec.args="--json"
103103
- `json-java21`: Core JSON API implementation (main library).
104104
- `json-java21-api-tracker`: API evolution tracking utilities.
105105
- `json-compatibility-suite`: JSON Test Suite compatibility validation.
106-
- `json-java21-schema`: JSON Schema validator (module guide below).
106+
- `json-java21-jtd`: JSON Type Definition (JTD) validator based on RFC 8927.
107107

108108
### Core Components
109109

@@ -176,16 +176,11 @@ IMPORTANT: Bugs in the main logic this code cannot be fixed in this repo they **
176176
- Workflow fetches upstream sources, parses both codebases with the Java compiler API, and reports matching/different/missing elements across modifiers, inheritance, methods, fields, and constructors.
177177
- Continuous integration prints the report daily. It does not fail or open issues on differences; to trigger notifications, either make the runner exit non-zero when `differentApi > 0` or parse the report and call `core.setFailed()` within CI.
178178

179-
### json-java21-schema (JSON Schema Validator)
180-
- Inherits all repository-wide logging and testing rules described above.
181-
- You MUST place an INFO-level JUL log statement at the top of every test method declaring execution.
182-
- All new tests MUST extend a configuration helper such as `JsonSchemaLoggingConfig` to ensure JUL levels respected.
183-
- WARNING: you cannot run `mvn -pl xxxx verify` at the top level it will not work.
184-
- You must run `cd -Djson.schema.strict=true -Djson.schema.metrics=csv -Djava.util.logging.ConsoleHandler.level=INFO`
185-
186-
#### Running Tests (Schema Module)
187-
- All prohibitions on output filtering apply. Do not pipe logs unless you must constrain an infinite stream, and even then examine a large sample (thousands of lines).
188-
- Remote location of `$(command -v mvnd || command -v mvn || command -v ./mvnw)` is the repository root; pass module selectors through it for schema-only runs.
179+
### json-java21-jtd (JTD Validator)
180+
- JSON Type Definition validator implementing RFC 8927 specification.
181+
- Provides eight mutually-exclusive schema forms for simple, predictable validation.
182+
- Uses stack-based validation with comprehensive error reporting.
183+
- Includes full RFC 8927 compliance test suite.
189184

190185
## Security Notes
191186
- Deep nesting can trigger StackOverflowError (stack exhaustion attacks).

README.md

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ References:
99
This project is not an official release; APIs and behaviour may change as upstream evolves.
1010
You can find this code on [Maven Central](https://central.sonatype.com/artifact/io.github.simbo1905.json/java.util.json).
1111

12-
To kick the tyres on the New JSON API this repo uses to implement a JSON Schema Validator which is released on Maven Central as [java.util.json.schema](https://central.sonatype.com/artifact/io.github.simbo1905.json/java.util.json.schema).
12+
To kick the tyres on the New JSON API this repo includes a JSON Type Definition (JTD) Validator implementing RFC 8927, released on Maven Central as part of this project.
1313

14-
We welcome contributes to the JSON Schema Validator incubating within this repo.
14+
We welcome contributions to the JTD Validator incubating within this repo.
1515

1616
## Usage Examples
1717

@@ -289,38 +289,54 @@ This is a simplified backport with the following changes from the original:
289289

290290
Such vulnerabilities existed at one point in the upstream OpenJDK sandbox implementation and were reported here for transparency. Until the upstream code is stable it is probably better to assume that such issue or similar may be present or may reappear. If you are only going to use this library in small cli programs where the json is configuration you write then you will not parse objects nested to tens of thousands of levels designed crash a parser. Yet you should not at this tiome expose this parser to the internet where someone can choose to attack it in that manner.
291291

292-
## JSON Schema Validator
292+
## JSON Type Definition (JTD) Validator
293293

294-
This repo contains an incubating schema validator that has the core JSON API as its only depenency. This sub project demonstrates how to build realistic JSON heavy logic using the API. It follows Data Oriented Programming principles: it compiles the JSON Schema into an immutable structure of records. For validation it parses the JSON document to the generic structure and uses the thread-safe parsed schema and a stack to visit and validate the parsed JSON.
294+
This repo contains an incubating JTD validator that has the core JSON API as its only dependency. This sub-project demonstrates how to build realistic JSON heavy logic using the API. It follows Data Oriented Programming principles: it compiles JTD schemas into an immutable structure of records. For validation it parses the JSON document to the generic structure and uses the thread-safe parsed schema and a stack to visit and validate the parsed JSON.
295295

296-
A simple JSON Schema validator is included (module: json-java21-schema).
296+
A complete JSON Type Definition validator is included (module: json-java21-jtd).
297297

298298
```java
299-
var schema = io.github.simbo1905.json.schema.JsonSchema.compile(
300-
jdk.sandbox.java.util.json.Json.parse("""
301-
{"type":"object","properties":{"name":{"type":"string"}},"required":["name"]}
302-
"""));
303-
var result = schema.validate(
304-
jdk.sandbox.java.util.json.Json.parse("{\"name\":\"Alice\"}")
305-
);
306-
// result.valid() => true
299+
import json.java21.jtd.Jtd;
300+
import jdk.sandbox.java.util.json.*;
301+
302+
// Compile JTD schema
303+
JsonValue schema = Json.parse("""
304+
{
305+
"properties": {
306+
"name": {"type": "string"},
307+
"age": {"type": "int32"}
308+
}
309+
}
310+
""");
311+
312+
// Validate JSON
313+
JsonValue data = Json.parse("{\"name\":\"Alice\",\"age\":30}");
314+
Jtd validator = new Jtd();
315+
Jtd.Result result = validator.validate(schema, data);
316+
// result.isValid() => true
307317
```
308318

309-
### JSON Schema Test Suite Metrics
319+
### JTD RFC 8927 Compliance
310320

311-
The validator now provides defensible compatibility statistics:
321+
The validator provides full RFC 8927 compliance with comprehensive test coverage:
312322

313323
```bash
314-
# Run with console metrics (default)
315-
$(command -v mvnd || command -v mvn || command -v ./mvnw) -pl json-java21-schema
316-
317-
# Export detailed JSON metrics
318-
$(command -v mvnd || command -v mvn || command -v ./mvnw) -pl json-java21-schema -Djson.schema.metrics=json
324+
# Run all JTD compliance tests
325+
$(command -v mvnd || command -v mvn || command -v ./mvnw) test -pl json-java21-jtd -Dtest=JtdSpecIT
319326

320-
# Export CSV metrics for analysis
321-
$(command -v mvnd || command -v mvn || command -v ./mvnw) -pl json-java21-schema -Djson.schema.metrics=csv
327+
# Run with detailed logging
328+
$(command -v mvnd || command -v mvn || command -v ./mvnw) test -pl json-java21-jtd -Djava.util.logging.ConsoleHandler.level=FINE
322329
```
323330

331+
Features:
332+
- ✅ Eight mutually-exclusive schema forms (RFC 8927 §2.2)
333+
- ✅ Standardized error format with instance and schema paths
334+
- ✅ Primitive type validation with proper ranges
335+
- ✅ Definition support with reference resolution
336+
- ✅ Timestamp format validation (RFC 3339 with leap seconds)
337+
- ✅ Discriminator tag exemption from additional properties
338+
- ✅ Stack-based validation preventing StackOverflowError
339+
324340
## Building
325341

326342
Requires JDK 21 or later. Build with Maven:
@@ -330,7 +346,7 @@ mvn clean compile
330346
mvn package
331347
```
332348

333-
Please see AGENTS.md for more guidence such as how to enabled logging when running the JSON Schema Validator.
349+
Please see AGENTS.md for more guidance such as how to enable logging when running the JTD Validator.
334350

335351
## Augmented Intelligence (AI) Welcomed
336352

0 commit comments

Comments
 (0)