Java SDK

Local validation of INHERIT estate documents in Java with bundled schemas. Supports Level 1 and Level 2 conformance with a simple static API.

Java v6.0.02 min read
Package: org.openinherit:sdk

Installation#

Gradle#

groovy
dependencies {
    implementation 'org.openinherit:sdk:6.0.0'
}

Maven#

xml
<dependency>
    <groupId>org.openinherit</groupId>
    <artifactId>sdk</artifactId>
    <version>6.0.0</version>
</dependency>

Requires Java 17 or later.

Quick start#

java
import org.openinherit.sdk.Validator;
import org.openinherit.sdk.ValidationResult;

String json = Files.readString(Path.of("estate.json"));
ValidationResult result = Validator.validate(json);

if (result.valid()) {
    System.out.printf("Valid (Level %d)%n", result.conformanceLevel());
} else {
    for (var error : result.errors()) {
        System.out.printf("  %s: %s%n", error.path(), error.message());
    }
}

API reference#

Validator.validate(String jsonDocument)#

Validates an INHERIT document, auto-detecting estate or catalogue mode from the $schema field.

Validator.validateEstate(String jsonDocument)#

Validates a document as an estate document regardless of its $schema field.

Validator.validateCatalogue(String jsonDocument)#

Validates a document as a catalogue document regardless of its $schema field.

Validator.validateLevel2(String jsonDocument)#

Performs Level 2 validation: JSON Schema validation followed by referential integrity checking. Every UUID cross-reference must resolve to an entity in the document.

Returns conformance level 0 (schema failed), 1 (schema passed, refs failed), or 2 (both passed).

ValidationResult#

java
public record ValidationResult(
    boolean valid,
    String schemaMode,
    List<ValidationError> errors,
    String disclaimer,
    int conformanceLevel
) {
    public record ValidationError(String path, String message) {}
}

Examples#

Level 2 validation#

java
ValidationResult result = Validator.validateLevel2(json);

switch (result.conformanceLevel()) {
    case 2 -> System.out.println("Fully conformant");
    case 1 -> System.out.println("Schema valid, broken references");
    case 0 -> System.out.println("Schema validation failed");
}

Validate a catalogue document#

java
ValidationResult result = Validator.validateCatalogue(catalogueJson);

Spring Boot endpoint#

java
@PostMapping("/validate")
public ValidationResult validate(@RequestBody String document) {
    return Validator.validate(document);
}

Get in touch

Have a question about INHERIT, or interested in becoming a partner? We'd love to hear from you.

By submitting this form, you agree to our Privacy Policy. Your data is processed by Formspark (EU) and retained until your enquiry is resolved.

or email hello@openinherit.org