Interface JsonSchemaValidator
JsonSchemaValidatorConfiguration.
The value to validate can be any object that the application's JsonMapper can serialize, a
JsonNode, or a String, which is parsed as JSON text. Implementations
compile a schema when it is first used and keep it compiled (schemas given as a String or a Map are
kept in a bounded cache). The returned sets are mutable and keep the order in which the errors were found.
Besides IOExceptions, implementations throw an IllegalArgumentException when no schema was
generated for a type, when a schema is invalid, or when a reference in a schema cannot be resolved.
The built-in implementation is provided by micronaut-json-schema-validator; the module
micronaut-json-schema-validator-networknt replaces it with one based on the NetworkNT JSON Schema Validator.
- Since:
- 1.0.0
- Author:
- Sergio del Amo
-
Method Summary
Modifier and TypeMethodDescription<T> @NonNull Set<? extends ValidationMessage> Validate Object based on types JSON schema.Set<? extends ValidationMessage> Validate Object against a JSON schema.Set<? extends ValidationMessage> Validate Object against a JSON schema.<T> @NonNull Set<? extends ValidationMessage> Validate JSON based on a types JSON schema.
-
Method Details
-
validate
<T> @NonNull Set<? extends ValidationMessage> validate(@NonNull String value, @NonNull Class<T> type) throws IOException Validate JSON based on a types JSON schema.- Type Parameters:
T- Type used to generate the JSON Schema- Parameters:
value- JSON text to validatetype- The type used to generate the JSON Schema- Returns:
- A set of validation messages. Empty if valid.
- Throws:
IOException- If an error occurs validating the JSON against the schema.
-
validate
<T> @NonNull Set<? extends ValidationMessage> validate(@NonNull Object value, @NonNull Class<T> type) throws IOException Validate Object based on types JSON schema.- Type Parameters:
T- Type used to generate the JSON Schema- Parameters:
value- Object to validate against a JSON schematype- The type used to generate the JSON Schema- Returns:
- A set of validation messages. Empty if valid.
- Throws:
IOException- If an error occurs validating the JSON against the schema.
-
validate
Set<? extends ValidationMessage> validate(@NonNull Object value, @NonNull Map<String, Object> jsonSchema) throws IOExceptionValidate Object against a JSON schema.- Parameters:
value- Object to validate against a JSON schemajsonSchema- The JSON Schema expressed as a Map- Returns:
- A set of validation messages. Empty if valid.
- Throws:
IOException- If an error occurs validating the JSON against the schema.
-
validate
Set<? extends ValidationMessage> validate(@NonNull Object value, @NonNull String jsonSchema) throws IOException Validate Object against a JSON schema.- Parameters:
value- Object to validate against a JSON schemajsonSchema- The JSON Schema expressed as JSON text- Returns:
- A set of validation messages. Empty if valid.
- Throws:
IOException- If an error occurs validating the JSON against the schema.
-