Interface JsonSchemaValidator
public interface JsonSchemaValidator
Interface for validating structured content against a JSON schema. This interface
defines a method to validate structured content based on the provided output schema.
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordRepresents the result of a validation operation. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidassertConforms(String context, Map<String, Object> schema) Asserts that the given schema document is a structurally valid JSON Schema.Validates the structured content against the provided JSON schema.validateSchema(Map<String, Object> schema) Validates that the given schema document itself conforms to JSON Schema 2020-12 (SEP-1613).
-
Method Details
-
assertConforms
Asserts that the given schema document is a structurally valid JSON Schema. Schemas without an explicit$schemadeclaration, or those that declare JSON Schema 2020-12, are validated against the 2020-12 meta-schema. Schemas that explicitly declare a different dialect are accepted without meta-schema validation. ThrowsIllegalArgumentExceptionif validation fails. Silently returns on null schema. The default implementation delegates tovalidateSchema(java.util.Map<java.lang.String, java.lang.Object>).- Parameters:
context- human-readable description of the schema's location (used in error messages)schema- the schema document to validate, ornull(no-op)- Throws:
IllegalArgumentException- if the schema is structurally invalid
-
validate
JsonSchemaValidator.ValidationResponse validate(Map<String, Object> schema, Object structuredContent) Validates the structured content against the provided JSON schema.- Parameters:
schema- The JSON schema to validate against.structuredContent- The structured content to validate.- Returns:
- A ValidationResponse indicating whether the validation was successful or not.
-
validateSchema
Validates that the given schema document itself conforms to JSON Schema 2020-12 (SEP-1613). Schemas that declare an explicit non-2020-12$schemadialect are skipped and considered valid. The default implementation is a no-op.- Parameters:
schema- the schema document to check- Returns:
- a ValidationResponse indicating conformance
-