Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
52ec5e7
Issue #89 Fix int32 type validation to reject decimal values like 3.14
simbo1905 Sep 27, 2025
bd738cb
Issue #89 Update CI test count to 461 after adding int32 decimal vali…
simbo1905 Sep 27, 2025
411fef7
Issue #89 Update CI test count to 463 after adding integer validation…
simbo1905 Sep 27, 2025
d4fd468
Issue #89 Update CI test count to 463 after adding integer validation…
simbo1905 Sep 27, 2025
cf16f71
Issue #91 Fix additionalProperties default value in JTD validator
simbo1905 Sep 27, 2025
60735a7
merge
simbo1905 Sep 28, 2025
bc1ae9d
Remove JtdExhaustiveTest from PR to allow merging bug fix
simbo1905 Sep 28, 2025
667fe3e
464
simbo1905 Sep 28, 2025
b1e876a
Merge remote-tracking branch 'origin/main' into feature/jqwik-propert…
simbo1905 Sep 28, 2025
e6877c3
Issue #94 Fix discriminator validation for simple type mappings
simbo1905 Sep 28, 2025
35b0632
Update CI test count and add PR creation instructions
simbo1905 Sep 28, 2025
d607df1
Merge branch 'main' into feature/jqwik-property-testing-88
simbo1905 Sep 28, 2025
16eef74
Issue #96 Add test case for nested elements properties bug
simbo1905 Sep 28, 2025
aa63d83
Update CI test count for new nested elements test
simbo1905 Sep 28, 2025
de41602
Merge branch 'main' into feature/jqwik-property-testing-88
simbo1905 Sep 28, 2025
971684e
pivot to strict rfc
simbo1905 Sep 28, 2025
bab95f9
wip
simbo1905 Sep 28, 2025
219b7a6
wip
simbo1905 Sep 28, 2025
dc41f40
wip
simbo1905 Sep 28, 2025
7c5c522
JtdExhaustiveTest.java
simbo1905 Sep 28, 2025
8cefcb7
ci test count
simbo1905 Sep 28, 2025
3b9f390
tidy up
simbo1905 Sep 28, 2025
4d24932
tidy
simbo1905 Sep 28, 2025
03a9c4e
code review feedback
simbo1905 Sep 28, 2025
35bafd6
bump
simbo1905 Sep 28, 2025
cc6c787
edits
simbo1905 Sep 28, 2025
76a8859
merge
simbo1905 Sep 28, 2025
6ab0386
docs
simbo1905 Sep 28, 2025
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
84 changes: 43 additions & 41 deletions json-java21-jtd/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,53 +46,54 @@ flowchart TD

## Core API Design

Following modern Java patterns, we use a single public sealed interface with package-private record implementations:
Following modern Java patterns, we use a package-private sealed interface with record implementations and a public facade class:

```java
package io.github.simbo1905.json.jtd;
package json.java21.jtd;

import jdk.sandbox.java.util.json.*;

public sealed interface JTDSchema
permits JTDSchema.EmptySchema,
JTDSchema.RefSchema,
JTDSchema.TypeSchema,
JTDSchema.EnumSchema,
JTDSchema.ElementsSchema,
JTDSchema.PropertiesSchema,
JTDSchema.ValuesSchema,
JTDSchema.DiscriminatorSchema {

/// Compile JTD schema from JSON
static JTDSchema compile(JsonValue schemaJson) {
// Parse and build immutable schema hierarchy
}

/// Validate JSON document against schema
default ValidationResult validate(JsonValue json) {
// Stack-based validation
}

/// Package-private sealed interface for schema types
sealed interface JtdSchema
permits JtdSchema.EmptySchema,
JtdSchema.RefSchema,
JtdSchema.TypeSchema,
JtdSchema.EnumSchema,
JtdSchema.ElementsSchema,
JtdSchema.PropertiesSchema,
JtdSchema.ValuesSchema,
JtdSchema.DiscriminatorSchema,
JtdSchema.NullableSchema {

/// Schema type records (package-private)
record EmptySchema() implements JTDSchema {}
record RefSchema(String ref) implements JTDSchema {}
record TypeSchema(PrimitiveType type) implements JTDSchema {}
record EnumSchema(Set<String> values) implements JTDSchema {}
record ElementsSchema(JTDSchema elements) implements JTDSchema {}
record EmptySchema() implements JtdSchema {}
record RefSchema(String ref, Map<String, JtdSchema> definitions) implements JtdSchema {}
record TypeSchema(PrimitiveType type) implements JtdSchema {}
record EnumSchema(Set<String> values) implements JtdSchema {}
record ElementsSchema(JtdSchema elements) implements JtdSchema {}
record PropertiesSchema(
Map<String, JTDSchema> properties,
Map<String, JTDSchema> optionalProperties,
Map<String, JtdSchema> properties,
Map<String, JtdSchema> optionalProperties,
boolean additionalProperties
) implements JTDSchema {}
record ValuesSchema(JTDSchema values) implements JTDSchema {}
) implements JtdSchema {}
record ValuesSchema(JtdSchema values) implements JtdSchema {}
record DiscriminatorSchema(
String discriminator,
Map<String, JTDSchema> mapping
) implements JTDSchema {}
Map<String, JtdSchema> mapping
) implements JtdSchema {}
record NullableSchema(JtdSchema nullable) implements JtdSchema {}
}

/// Public facade class for JTD operations
public class Jtd {
/// Compile and validate JSON against JTD schema
public Result validate(JsonValue schema, JsonValue instance) {
JtdSchema jtdSchema = compileSchema(schema);
return validateWithStack(jtdSchema, instance);
}

/// Validation result
record ValidationResult(boolean valid, List<ValidationError> errors) {}
record ValidationError(String instancePath, String schemaPath, String message) {}
public record Result(boolean isValid, List<String> errors) {}
}
```

Expand Down Expand Up @@ -232,7 +233,10 @@ record CompiledSchema(

```java
import jdk.sandbox.java.util.json.*;
import io.github.simbo1905.json.jtd.JTDSchema;
import json.java21.jtd.Jtd;

// Create JTD validator
Jtd jtd = new Jtd();

// Compile JTD schema
String schemaJson = """
Expand All @@ -248,18 +252,16 @@ String schemaJson = """
}
""";

JTDSchema schema = JTDSchema.compile(Json.parse(schemaJson));

// Validate JSON
String json = """
{"id": "123", "name": "Alice", "age": 30, "email": "[email protected]"}
""";

JTDSchema.ValidationResult result = schema.validate(Json.parse(json));
Jtd.Result result = jtd.validate(Json.parse(schemaJson), Json.parse(json));

if (!result.valid()) {
if (!result.isValid()) {
for (var error : result.errors()) {
System.out.println(error.instancePath() + ": " + error.message());
System.out.println(error);
}
}
```
Expand Down
Loading