Package dev.harrel.jsonschema
Class ValidatorFactory
java.lang.Object
dev.harrel.jsonschema.ValidatorFactory
Configurable factory for
Validator class. Provides methods for ad-hoc validation, which parse schema each time they are invoked.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates new instance ofValidatorusing current configuration.Validates JSON instance against schema.Validates JSON instance against schema.Validates JSON instance against schema.Validates JSON instance against schema.Validates JSON instance against schema.Validates JSON instance against schema.Validates JSON instance against schema.Validates JSON instance against schema.Validates JSON instance against schema.withDialect(Dialect dialect) SetsDialect.withDisabledSchemaValidation(boolean disabledSchemaValidation) Disables schema validation against meta-schemas.withEvaluatorFactory(EvaluatorFactory evaluatorFactory) Sets additionalEvaluatorFactoryto be used alongside with the coreEvaluatorFactoryprovided byDialect.withJsonNodeFactory(JsonNodeFactory jsonNodeFactory) SetsJsonNodeFactory.withSchemaResolver(SchemaResolver schemaResolver) ComposesSchemaResolverwith default schema resolver.
-
Constructor Details
-
ValidatorFactory
public ValidatorFactory()
-
-
Method Details
-
createValidator
Creates new instance ofValidatorusing current configuration.- Returns:
- new
Validatorinstance
-
withDialect
SetsDialect. Provided default isDialects.Draft2020Dialect.- Parameters:
dialect-Dialectto be used- Returns:
- self
-
withEvaluatorFactory
Sets additionalEvaluatorFactoryto be used alongside with the coreEvaluatorFactoryprovided byDialect. This is the best way to provide custom keyword support.- Parameters:
evaluatorFactory-EvaluatorFactoryto be used- Returns:
- self
-
withJsonNodeFactory
SetsJsonNodeFactory. Provided default isJacksonNode.Factory.- Parameters:
jsonNodeFactory-JsonNodeFactoryto be used- Returns:
- self
-
withSchemaResolver
ComposesSchemaResolverwith default schema resolver. The default schema resolver resolves only official specification meta-schemas. Meta-schemas are loaded from classpath.- Parameters:
schemaResolver-SchemaResolverto be used- Returns:
- self
- See Also:
-
withDisabledSchemaValidation
Disables schema validation against meta-schemas. This also disables vocabulary specific semantics. $schema keyword will be ignored.- Parameters:
disabledSchemaValidation- if schema validation should be disabled- Returns:
- self
-
validate
Validates JSON instance against schema. Each invocation creates temporaryValidatorwhich parses schema from scratch. If you want to validate multiple JSON instances against same schema - please usecreateValidator()and useValidatorclass directly.- Parameters:
rawSchema- string representation of schema JSONrawInstance- string representation of instance JSON- Returns:
- validation result
-
validate
Validates JSON instance against schema. Each invocation creates temporaryValidatorwhich parses schema from scratch. If you want to validate multiple JSON instances against same schema - please usecreateValidator()and useValidatorclass directly.- Parameters:
schemaProviderNode- object representing schema JSON for currently setJsonNodeFactory. E.g.com.fasterxml.jackson.databind.JsonNodefor defaultJsonNodeFactory(JacksonNode.Factory)rawInstance- string representation of instance JSON- Returns:
- validation result
- See Also:
-
validate
Validates JSON instance against schema. Each invocation creates temporaryValidatorwhich parses schema from scratch. If you want to validate multiple JSON instances against same schema - please usecreateValidator()and useValidatorclass directly.- Parameters:
schemaNode-JsonNodeschema JSON, which could be created viaJsonNodeFactoryrawInstance- string representation of instance JSON- Returns:
- validation result
- See Also:
-
validate
Validates JSON instance against schema. Each invocation creates temporaryValidatorwhich parses schema from scratch. If you want to validate multiple JSON instances against same schema - please usecreateValidator()and useValidatorclass directly.- Parameters:
rawSchema- string representation of schema JSONinstanceProviderNode- object representing instance JSON for currently setJsonNodeFactory. E.g.com.fasterxml.jackson.databind.JsonNodefor defaultJsonNodeFactory(JacksonNode.Factory)- Returns:
- validation result
- See Also:
-
validate
Validates JSON instance against schema. Each invocation creates temporaryValidatorwhich parses schema from scratch. If you want to validate multiple JSON instances against same schema - please usecreateValidator()and useValidatorclass directly.- Parameters:
schemaProviderNode- object representing schema JSON for currently setJsonNodeFactory. E.g.com.fasterxml.jackson.databind.JsonNodefor defaultJsonNodeFactory(JacksonNode.Factory)instanceProviderNode- object representing instance JSON for currently setJsonNodeFactory. E.g.com.fasterxml.jackson.databind.JsonNodefor defaultJsonNodeFactory(JacksonNode.Factory)- Returns:
- validation result
- See Also:
-
validate
Validates JSON instance against schema. Each invocation creates temporaryValidatorwhich parses schema from scratch. If you want to validate multiple JSON instances against same schema - please usecreateValidator()and useValidatorclass directly.- Parameters:
schemaNode-JsonNodeschema JSON, which could be created viaJsonNodeFactoryinstanceProviderNode- object representing instance JSON for currently setJsonNodeFactory. E.g.com.fasterxml.jackson.databind.JsonNodefor defaultJsonNodeFactory(JacksonNode.Factory)- Returns:
- validation result
- See Also:
-
validate
Validates JSON instance against schema. Each invocation creates temporaryValidatorwhich parses schema from scratch. If you want to validate multiple JSON instances against same schema - please usecreateValidator()and useValidatorclass directly.- Parameters:
rawSchema- string representation of schema JSONinstanceNode-JsonNodeinstance JSON, which could be created viaJsonNodeFactory- Returns:
- validation result
- See Also:
-
validate
Validates JSON instance against schema. Each invocation creates temporaryValidatorwhich parses schema from scratch. If you want to validate multiple JSON instances against same schema - please usecreateValidator()and useValidatorclass directly.- Parameters:
schemaProviderNode- object representing schema JSON for currently setJsonNodeFactory. E.g.com.fasterxml.jackson.databind.JsonNodefor defaultJsonNodeFactory(JacksonNode.Factory)instanceNode-JsonNodeinstance JSON, which could be created viaJsonNodeFactory- Returns:
- validation result
- See Also:
-
validate
Validates JSON instance against schema. Each invocation creates temporaryValidatorwhich parses schema from scratch. If you want to validate multiple JSON instances against same schema - please usecreateValidator()and useValidatorclass directly.- Parameters:
schemaNode-JsonNodeschema JSON, which could be created viaJsonNodeFactoryinstanceNode-JsonNodeinstance JSON, which could be created viaJsonNodeFactory- Returns:
- validation result
- See Also:
-