Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ jobs:
for k in totals: totals[k]+=int(r.get(k,'0'))
except Exception:
pass
exp_tests=4436
exp_skipped=1692
exp_tests=460
exp_skipped=0
if totals['tests']!=exp_tests or totals['skipped']!=exp_skipped:
print(f"Unexpected test totals: {totals} != expected tests={exp_tests}, skipped={exp_skipped}")
sys.exit(1)
Expand Down
19 changes: 7 additions & 12 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ LOG.fine(() -> "PERFORMANCE WARNING: Validation stack processing " + count + ...
```

### Additional Guidance
- 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)`.
- Logging rules apply globally. The helper superclass ensures JUL configuration remains compatible with `$(command -v mvnd || command -v mvn || command -v ./mvnw)`.

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

### Core Components

Expand Down Expand Up @@ -176,16 +176,11 @@ IMPORTANT: Bugs in the main logic this code cannot be fixed in this repo they **
- 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.
- 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.

### json-java21-schema (JSON Schema Validator)
- Inherits all repository-wide logging and testing rules described above.
- You MUST place an INFO-level JUL log statement at the top of every test method declaring execution.
- All new tests MUST extend a configuration helper such as `JsonSchemaLoggingConfig` to ensure JUL levels respected.
- WARNING: you cannot run `mvn -pl xxxx verify` at the top level it will not work.
- You must run `cd -Djson.schema.strict=true -Djson.schema.metrics=csv -Djava.util.logging.ConsoleHandler.level=INFO`

#### Running Tests (Schema Module)
- 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).
- 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.
### json-java21-jtd (JTD Validator)
- JSON Type Definition validator implementing RFC 8927 specification.
- Provides eight mutually-exclusive schema forms for simple, predictable validation.
- Uses stack-based validation with comprehensive error reporting.
- Includes full RFC 8927 compliance test suite.

## Security Notes
- Deep nesting can trigger StackOverflowError (stack exhaustion attacks).
Expand Down
62 changes: 39 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ References:
This project is not an official release; APIs and behaviour may change as upstream evolves.
You can find this code on [Maven Central](https://central.sonatype.com/artifact/io.github.simbo1905.json/java.util.json).

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).
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.

We welcome contributes to the JSON Schema Validator incubating within this repo.
We welcome contributions to the JTD Validator incubating within this repo.

## Usage Examples

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

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.

## JSON Schema Validator
## JSON Type Definition (JTD) Validator

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.
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.

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

```java
var schema = io.github.simbo1905.json.schema.JsonSchema.compile(
jdk.sandbox.java.util.json.Json.parse("""
{"type":"object","properties":{"name":{"type":"string"}},"required":["name"]}
"""));
var result = schema.validate(
jdk.sandbox.java.util.json.Json.parse("{\"name\":\"Alice\"}")
);
// result.valid() => true
import json.java21.jtd.Jtd;
import jdk.sandbox.java.util.json.*;

// Compile JTD schema
JsonValue schema = Json.parse("""
{
"properties": {
"name": {"type": "string"},
"age": {"type": "int32"}
}
}
""");

// Validate JSON
JsonValue data = Json.parse("{\"name\":\"Alice\",\"age\":30}");
Jtd validator = new Jtd();
Jtd.Result result = validator.validate(schema, data);
// result.isValid() => true
```

### JSON Schema Test Suite Metrics
### JTD RFC 8927 Compliance

The validator now provides defensible compatibility statistics:
The validator provides full RFC 8927 compliance with comprehensive test coverage:

```bash
# Run with console metrics (default)
$(command -v mvnd || command -v mvn || command -v ./mvnw) -pl json-java21-schema

# Export detailed JSON metrics
$(command -v mvnd || command -v mvn || command -v ./mvnw) -pl json-java21-schema -Djson.schema.metrics=json
# Run all JTD compliance tests
$(command -v mvnd || command -v mvn || command -v ./mvnw) test -pl json-java21-jtd -Dtest=JtdSpecIT

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

Features:
- βœ… Eight mutually-exclusive schema forms (RFC 8927 Β§2.2)
- βœ… Standardized error format with instance and schema paths
- βœ… Primitive type validation with proper ranges
- βœ… Definition support with reference resolution
- βœ… Timestamp format validation (RFC 3339 with leap seconds)
- βœ… Discriminator tag exemption from additional properties
- βœ… Stack-based validation preventing StackOverflowError

## Building

Requires JDK 21 or later. Build with Maven:
Expand All @@ -330,7 +346,7 @@ mvn clean compile
mvn package
```

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

## Augmented Intelligence (AI) Welcomed

Expand Down
Loading