Class JsonSchema
- java.lang.Object
-
- com.networknt.schema.ValidationMessageHandler
-
- com.networknt.schema.BaseJsonValidator
-
- com.networknt.schema.JsonSchema
-
- All Implemented Interfaces:
JsonValidator
,JsonSchemaWalker
public class JsonSchema extends BaseJsonValidator
Used for creating a schema with validators for validating inputs. This is created usingJsonSchemaFactory.getInstance(VersionFlag, Consumer)
and should be cached for performance.This is the core of json constraint implementation. It parses json constraint file and generates JsonValidators. The class is thread safe, once it is constructed, it can be used to validate multiple json data concurrently.
JsonSchema instances are thread-safe provided its configuration is not modified.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.networknt.schema.BaseJsonValidator
BaseJsonValidator.JsonNodePathJsonPath, BaseJsonValidator.JsonNodePathJsonPointer, BaseJsonValidator.JsonNodePathLegacy
-
-
Field Summary
-
Fields inherited from class com.networknt.schema.BaseJsonValidator
schemaNode, suppressSubSchemaRetrieval, validationContext
-
Fields inherited from class com.networknt.schema.ValidationMessageHandler
errorMessage, errorMessageKeyword, errorMessageType, evaluationParentSchema, evaluationPath, keyword, messageSource, parentSchema, schemaLocation
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JsonSchema(List<JsonValidator> validators, boolean validatorsLoaded, boolean recursiveAnchor, TypeValidator typeValidator, String id, boolean suppressSubSchemaRetrieval, com.fasterxml.jackson.databind.JsonNode schemaNode, ValidationContext validationContext, ErrorMessageType errorMessageType, String errorMessageKeyword, MessageSource messageSource, Keyword keyword, JsonSchema parentSchema, SchemaLocation schemaLocation, JsonNodePath evaluationPath, JsonSchema evaluationParentSchema, Map<String,String> errorMessage)
Constructor to create a copy using fields.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ExecutionContext
createExecutionContext()
Creates an execution context.JsonSchema
findAncestor()
JsonSchema
findLexicalRoot()
JsonSchema
findSchemaResourceRoot()
Finds the root of the schema resource.JsonSchema
fromRef(JsonSchema refEvaluationParentSchema, JsonNodePath refEvaluationPath)
Creates a schema using the current one as a template with the parent as the ref.String
getId()
protected com.fasterxml.jackson.databind.JsonNode
getNode(com.fasterxml.jackson.databind.JsonNode node, Object propertyOrIndex)
protected com.fasterxml.jackson.databind.JsonNode
getNode(Object propertyOrIndex)
JsonSchema
getRefSchema(JsonNodePath fragment)
com.fasterxml.jackson.databind.JsonNode
getRefSchemaNode(String ref)
Find the schema node for $ref attribute.JsonSchema
getSubSchema(JsonNodePath fragment)
Gets the sub schema given the json pointer fragment.TypeValidator
getTypeValidator()
ValidationContext
getValidationContext()
List<JsonValidator>
getValidators()
boolean
hasTypeValidator()
void
initializeValidators()
Initializes the validators'JsonSchema
instances.boolean
isRecursiveAnchor()
boolean
isSchemaResourceRoot()
Determines if this schema resource is a schema resource root.String
toString()
END OF WALK METHODSSet<ValidationMessage>
validate(com.fasterxml.jackson.databind.JsonNode rootNode)
Validate the given root JsonNode, starting at the root of the data path.Set<ValidationMessage>
validate(com.fasterxml.jackson.databind.JsonNode rootNode, ExecutionContextCustomizer executionCustomizer)
Validate the given root JsonNode, starting at the root of the data path.<T> T
validate(com.fasterxml.jackson.databind.JsonNode rootNode, OutputFormat<T> format)
Validates the given root JsonNode, starting at the root of the data path.<T> T
validate(com.fasterxml.jackson.databind.JsonNode rootNode, OutputFormat<T> format, ExecutionContextCustomizer executionCustomizer)
Validates the given root JsonNode, starting at the root of the data path.<T> T
validate(com.fasterxml.jackson.databind.JsonNode rootNode, OutputFormat<T> format, Consumer<ExecutionContext> executionCustomizer)
Validates the given root JsonNode, starting at the root of the data path.Set<ValidationMessage>
validate(com.fasterxml.jackson.databind.JsonNode rootNode, Consumer<ExecutionContext> executionCustomizer)
Validate the given root JsonNode, starting at the root of the data path.Set<ValidationMessage>
validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode jsonNode, com.fasterxml.jackson.databind.JsonNode rootNode, JsonNodePath instanceLocation)
START OF VALIDATE METHODS<T> T
validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> format)
Validates to a format.<T> T
validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> format, ExecutionContextCustomizer executionCustomizer)
Validates to a format.Set<ValidationMessage>
validate(String input, InputFormat inputFormat)
Validate the given input string using the input format, starting at the root of the data path.Set<ValidationMessage>
validate(String input, InputFormat inputFormat, ExecutionContextCustomizer executionCustomizer)
Validate the given input string using the input format, starting at the root of the data path.<T> T
validate(String input, InputFormat inputFormat, OutputFormat<T> format)
Validates the given input string using the input format, starting at the root of the data path.<T> T
validate(String input, InputFormat inputFormat, OutputFormat<T> format, ExecutionContextCustomizer executionCustomizer)
Validates the given input string using the input format, starting at the root of the data path.<T> T
validate(String input, InputFormat inputFormat, OutputFormat<T> format, Consumer<ExecutionContext> executionCustomizer)
Validates the given input string using the input format, starting at the root of the data path.Set<ValidationMessage>
validate(String input, InputFormat inputFormat, Consumer<ExecutionContext> executionCustomizer)
Validate the given input string using the input format, starting at the root of the data path.ValidationResult
validateAndCollect(com.fasterxml.jackson.databind.JsonNode node)
Deprecated.ValidationResult
validateAndCollect(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node)
Deprecated.ValidationResult
walk(com.fasterxml.jackson.databind.JsonNode node, boolean validate)
Walk the JSON node.<T> T
walk(com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> outputFormat, boolean validate)
Walk the JSON node.ValidationResult
walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, boolean validate)
Walk the JSON node.ValidationResult
walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, boolean validate, ExecutionContextCustomizer executionCustomizer)
Walk the JSON node.ValidationResult
walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, boolean validate, Consumer<ExecutionContext> executionCustomizer)
Walk the JSON node.Set<ValidationMessage>
walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, JsonNodePath instanceLocation, boolean shouldValidateSchema)
This is default implementation of walk method.<T> T
walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> outputFormat, boolean validate, ExecutionContextCustomizer executionCustomizer)
Walk the JSON node.<T> T
walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> outputFormat, boolean validate, Consumer<ExecutionContext> executionCustomizer)
Walk the JSON node.ValidationResult
walk(ExecutionContext executionContext, String input, InputFormat inputFormat, boolean validate)
Walk the input.ValidationResult
walk(ExecutionContext executionContext, String input, InputFormat inputFormat, boolean validate, ExecutionContextCustomizer executionCustomizer)
Walk the input.<T> T
walk(ExecutionContext executionContext, String input, InputFormat inputFormat, OutputFormat<T> outputFormat, boolean validate)
Walk the input.<T> T
walk(ExecutionContext executionContext, String input, InputFormat inputFormat, OutputFormat<T> outputFormat, boolean validate, ExecutionContextCustomizer executionCustomizer)
Walk the input.ValidationResult
walk(String input, InputFormat inputFormat, boolean validate)
Walk the input.ValidationResult
walk(String input, InputFormat inputFormat, boolean validate, ExecutionContextCustomizer executionCustomizer)
Walk the input.ValidationResult
walk(String input, InputFormat inputFormat, boolean validate, Consumer<ExecutionContext> executionCustomizer)
Walk the input.ValidationResult
walkAtNode(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, JsonNodePath instanceLocation, boolean validate)
Walk at the node.JsonSchema
withConfig(SchemaValidatorsConfig config)
-
Methods inherited from class com.networknt.schema.BaseJsonValidator
atRoot, checkDiscriminatorMatch, collectAnnotations, collectAnnotations, debug, equals, fetchSubSchemaNode, getEvaluationParentSchema, getEvaluationPath, getKeyword, getNodeFieldType, getParentSchema, getSchemaLocation, getSchemaNode, hasAdjacentKeywordInEvaluationPath, message, preloadJsonSchemas, putAnnotation, registerAndMergeDiscriminator, validate
-
Methods inherited from class com.networknt.schema.ValidationMessageHandler
getErrorMessage, getErrorMessageType, getMessageNode
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.networknt.schema.JsonValidator
preloadJsonSchema
-
-
-
-
Constructor Detail
-
JsonSchema
protected JsonSchema(List<JsonValidator> validators, boolean validatorsLoaded, boolean recursiveAnchor, TypeValidator typeValidator, String id, boolean suppressSubSchemaRetrieval, com.fasterxml.jackson.databind.JsonNode schemaNode, ValidationContext validationContext, ErrorMessageType errorMessageType, String errorMessageKeyword, MessageSource messageSource, Keyword keyword, JsonSchema parentSchema, SchemaLocation schemaLocation, JsonNodePath evaluationPath, JsonSchema evaluationParentSchema, Map<String,String> errorMessage)
Constructor to create a copy using fields.- Parameters:
validators
- the validatorsvalidatorsLoaded
- whether the validators are preloadedrecursiveAnchor
- whether this is has a recursive anchortypeValidator
- the type validatorid
- the idsuppressSubSchemaRetrieval
- to suppress sub schema retrievalschemaNode
- the schema nodevalidationContext
- the validation contexterrorMessageType
- the error message typeerrorMessageKeyword
- the error message keywordmessageSource
- the message sourcekeyword
- the keywordparentSchema
- the parent schemaschemaLocation
- the schema locationevaluationPath
- the evaluation pathevaluationParentSchema
- the evaluation parent schemaerrorMessage
- the error message
-
-
Method Detail
-
fromRef
public JsonSchema fromRef(JsonSchema refEvaluationParentSchema, JsonNodePath refEvaluationPath)
Creates a schema using the current one as a template with the parent as the ref.This is typically used if this schema is a schema resource that can be pointed to by various references.
- Parameters:
refEvaluationParentSchema
- the parent refrefEvaluationPath
- the ref evaluation path- Returns:
- the schema
-
withConfig
public JsonSchema withConfig(SchemaValidatorsConfig config)
-
getValidationContext
public ValidationContext getValidationContext()
-
getRefSchemaNode
public com.fasterxml.jackson.databind.JsonNode getRefSchemaNode(String ref)
Find the schema node for $ref attribute.- Parameters:
ref
- String- Returns:
- JsonNode
-
getRefSchema
public JsonSchema getRefSchema(JsonNodePath fragment)
-
getSubSchema
public JsonSchema getSubSchema(JsonNodePath fragment)
Gets the sub schema given the json pointer fragment.- Parameters:
fragment
- the json pointer fragment- Returns:
- the schema
-
getNode
protected com.fasterxml.jackson.databind.JsonNode getNode(Object propertyOrIndex)
-
getNode
protected com.fasterxml.jackson.databind.JsonNode getNode(com.fasterxml.jackson.databind.JsonNode node, Object propertyOrIndex)
-
findLexicalRoot
public JsonSchema findLexicalRoot()
-
findSchemaResourceRoot
public JsonSchema findSchemaResourceRoot()
Finds the root of the schema resource.This is either the schema document root or the subschema resource root.
- Returns:
- the root of the schema
-
isSchemaResourceRoot
public boolean isSchemaResourceRoot()
Determines if this schema resource is a schema resource root.This is either the schema document root or the subschema resource root.
- Returns:
- if this schema is a schema resource root
-
getId
public String getId()
-
findAncestor
public JsonSchema findAncestor()
-
validate
public Set<ValidationMessage> validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode jsonNode, com.fasterxml.jackson.databind.JsonNode rootNode, JsonNodePath instanceLocation)
START OF VALIDATE METHODS- Parameters:
executionContext
- ExecutionContextjsonNode
- JsonNoderootNode
- JsonNodeinstanceLocation
- JsonNodePath- Returns:
- A list of ValidationMessage if there is any validation error, or an empty list if there is no error.
-
validate
public Set<ValidationMessage> validate(com.fasterxml.jackson.databind.JsonNode rootNode)
Validate the given root JsonNode, starting at the root of the data path.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Parameters:
rootNode
- the root node- Returns:
- A list of ValidationMessage if there is any validation error, or an empty list if there is no error.
-
validate
public Set<ValidationMessage> validate(com.fasterxml.jackson.databind.JsonNode rootNode, ExecutionContextCustomizer executionCustomizer)
Validate the given root JsonNode, starting at the root of the data path.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Parameters:
rootNode
- the root nodeexecutionCustomizer
- the execution customizer- Returns:
- the assertions
-
validate
public Set<ValidationMessage> validate(com.fasterxml.jackson.databind.JsonNode rootNode, Consumer<ExecutionContext> executionCustomizer)
Validate the given root JsonNode, starting at the root of the data path.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Parameters:
rootNode
- the root nodeexecutionCustomizer
- the execution customizer- Returns:
- the assertions
-
validate
public <T> T validate(com.fasterxml.jackson.databind.JsonNode rootNode, OutputFormat<T> format)
Validates the given root JsonNode, starting at the root of the data path. The output will be formatted using the formatter specified.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Type Parameters:
T
- the result type- Parameters:
rootNode
- the root nodeformat
- the formatter- Returns:
- the result
-
validate
public <T> T validate(com.fasterxml.jackson.databind.JsonNode rootNode, OutputFormat<T> format, ExecutionContextCustomizer executionCustomizer)
Validates the given root JsonNode, starting at the root of the data path. The output will be formatted using the formatter specified.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Type Parameters:
T
- the result type- Parameters:
rootNode
- the root nodeformat
- the formatterexecutionCustomizer
- the execution customizer- Returns:
- the result
-
validate
public <T> T validate(com.fasterxml.jackson.databind.JsonNode rootNode, OutputFormat<T> format, Consumer<ExecutionContext> executionCustomizer)
Validates the given root JsonNode, starting at the root of the data path. The output will be formatted using the formatter specified.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Type Parameters:
T
- the result type- Parameters:
rootNode
- the root nodeformat
- the formatterexecutionCustomizer
- the execution customizer- Returns:
- the result
-
validate
public Set<ValidationMessage> validate(String input, InputFormat inputFormat)
Validate the given input string using the input format, starting at the root of the data path.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Parameters:
input
- the inputinputFormat
- the inputFormat- Returns:
- A list of ValidationMessage if there is any validation error, or an empty list if there is no error.
-
validate
public Set<ValidationMessage> validate(String input, InputFormat inputFormat, ExecutionContextCustomizer executionCustomizer)
Validate the given input string using the input format, starting at the root of the data path.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Parameters:
input
- the inputinputFormat
- the inputFormatexecutionCustomizer
- the execution customizer- Returns:
- the assertions
-
validate
public Set<ValidationMessage> validate(String input, InputFormat inputFormat, Consumer<ExecutionContext> executionCustomizer)
Validate the given input string using the input format, starting at the root of the data path.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Parameters:
input
- the inputinputFormat
- the inputFormatexecutionCustomizer
- the execution customizer- Returns:
- the assertions
-
validate
public <T> T validate(String input, InputFormat inputFormat, OutputFormat<T> format)
Validates the given input string using the input format, starting at the root of the data path. The output will be formatted using the formatter specified.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Type Parameters:
T
- the result type- Parameters:
input
- the inputinputFormat
- the inputFormatformat
- the formatter- Returns:
- the result
-
validate
public <T> T validate(String input, InputFormat inputFormat, OutputFormat<T> format, ExecutionContextCustomizer executionCustomizer)
Validates the given input string using the input format, starting at the root of the data path. The output will be formatted using the formatter specified.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Type Parameters:
T
- the result type- Parameters:
input
- the inputinputFormat
- the inputFormatformat
- the formatterexecutionCustomizer
- the execution customizer- Returns:
- the result
-
validate
public <T> T validate(String input, InputFormat inputFormat, OutputFormat<T> format, Consumer<ExecutionContext> executionCustomizer)
Validates the given input string using the input format, starting at the root of the data path. The output will be formatted using the formatter specified.Note that since Draft 2019-09 by default format generates only annotations and not assertions.
Use
ExecutionConfig.setFormatAssertionsEnabled(Boolean)
to override the default.- Type Parameters:
T
- the result type- Parameters:
input
- the inputinputFormat
- the inputFormatformat
- the formatterexecutionCustomizer
- the execution customizer- Returns:
- the result
-
validate
public <T> T validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> format)
Validates to a format.- Type Parameters:
T
- the result type- Parameters:
executionContext
- the execution contextnode
- the nodeformat
- the format- Returns:
- the result
-
validate
public <T> T validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> format, ExecutionContextCustomizer executionCustomizer)
Validates to a format.- Type Parameters:
T
- the result type- Parameters:
executionContext
- the execution contextnode
- the nodeformat
- the formatexecutionCustomizer
- the customizer- Returns:
- the result
-
validateAndCollect
@Deprecated public ValidationResult validateAndCollect(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node)
Deprecated.Deprecated. Initialize the CollectorContext externally and call loadCollectors when done.- Parameters:
executionContext
- ExecutionContextnode
- JsonNode- Returns:
- ValidationResult
-
validateAndCollect
@Deprecated public ValidationResult validateAndCollect(com.fasterxml.jackson.databind.JsonNode node)
Deprecated.Deprecated. Initialize the CollectorContext externally and call loadCollectors when done.- Parameters:
node
- JsonNode- Returns:
- ValidationResult
-
walk
public ValidationResult walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, boolean validate, ExecutionContextCustomizer executionCustomizer)
Walk the JSON node.- Parameters:
executionContext
- the execution contextnode
- the inputvalidate
- true to validate the input against the schemaexecutionCustomizer
- the customizer- Returns:
- the validation result
-
walk
public <T> T walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> outputFormat, boolean validate, ExecutionContextCustomizer executionCustomizer)
Walk the JSON node.- Type Parameters:
T
- the result type- Parameters:
executionContext
- the execution contextnode
- the inputoutputFormat
- the output formatvalidate
- true to validate the input against the schemaexecutionCustomizer
- the customizer- Returns:
- the validation result
-
walk
public ValidationResult walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, boolean validate, Consumer<ExecutionContext> executionCustomizer)
Walk the JSON node.- Parameters:
executionContext
- the execution contextnode
- the inputvalidate
- true to validate the input against the schemaexecutionCustomizer
- the customizer- Returns:
- the validation result
-
walk
public <T> T walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> outputFormat, boolean validate, Consumer<ExecutionContext> executionCustomizer)
Walk the JSON node.- Type Parameters:
T
- the result type- Parameters:
executionContext
- the execution contextnode
- the inputoutputFormat
- the output formatvalidate
- true to validate the input against the schemaexecutionCustomizer
- the customizer- Returns:
- the validation result
-
walk
public ValidationResult walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, boolean validate)
Walk the JSON node.- Parameters:
executionContext
- the execution contextnode
- the inputvalidate
- true to validate the input against the schema- Returns:
- the validation result
-
walk
public ValidationResult walk(ExecutionContext executionContext, String input, InputFormat inputFormat, boolean validate)
Walk the input.- Parameters:
executionContext
- the execution contextinput
- the inputinputFormat
- the input formatvalidate
- true to validate the input against the schema- Returns:
- the validation result
-
walk
public <T> T walk(ExecutionContext executionContext, String input, InputFormat inputFormat, OutputFormat<T> outputFormat, boolean validate)
Walk the input.- Type Parameters:
T
- the result type- Parameters:
executionContext
- the execution contextinput
- the inputinputFormat
- the input formatoutputFormat
- the output formatvalidate
- true to validate the input against the schema- Returns:
- the validation result
-
walk
public ValidationResult walk(ExecutionContext executionContext, String input, InputFormat inputFormat, boolean validate, ExecutionContextCustomizer executionCustomizer)
Walk the input.- Parameters:
executionContext
- the execution contextinput
- the inputinputFormat
- the input formatvalidate
- true to validate the input against the schemaexecutionCustomizer
- the customizer- Returns:
- the validation result
-
walk
public <T> T walk(ExecutionContext executionContext, String input, InputFormat inputFormat, OutputFormat<T> outputFormat, boolean validate, ExecutionContextCustomizer executionCustomizer)
Walk the input.- Type Parameters:
T
- the result type- Parameters:
executionContext
- the execution contextinput
- the inputinputFormat
- the input formatoutputFormat
- the output formatvalidate
- true to validate the input against the schemaexecutionCustomizer
- the customizer- Returns:
- the validation result
-
walk
public ValidationResult walk(com.fasterxml.jackson.databind.JsonNode node, boolean validate)
Walk the JSON node.- Parameters:
node
- the inputvalidate
- true to validate the input against the schema- Returns:
- the validation result
-
walk
public <T> T walk(com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> outputFormat, boolean validate)
Walk the JSON node.- Type Parameters:
T
- the result type- Parameters:
node
- the inputvalidate
- true to validate the input against the schemaoutputFormat
- the output format- Returns:
- the validation result
-
walk
public ValidationResult walk(String input, InputFormat inputFormat, boolean validate)
Walk the input.- Parameters:
input
- the inputinputFormat
- the input formatvalidate
- true to validate the input against the schema- Returns:
- the validation result
-
walk
public ValidationResult walk(String input, InputFormat inputFormat, boolean validate, ExecutionContextCustomizer executionCustomizer)
Walk the input.- Parameters:
input
- the inputinputFormat
- the input formatvalidate
- true to validate the input against the schemaexecutionCustomizer
- the customizer- Returns:
- the validation result
-
walk
public ValidationResult walk(String input, InputFormat inputFormat, boolean validate, Consumer<ExecutionContext> executionCustomizer)
Walk the input.- Parameters:
input
- the inputinputFormat
- the input formatvalidate
- true to validate the input against the schemaexecutionCustomizer
- the customizer- Returns:
- the validation result
-
walkAtNode
public ValidationResult walkAtNode(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, JsonNodePath instanceLocation, boolean validate)
Walk at the node.- Parameters:
executionContext
- the execution contentnode
- the current noderootNode
- the root nodeinstanceLocation
- the instance locationvalidate
- true to validate the input against the schema- Returns:
- the validation result
-
walk
public Set<ValidationMessage> walk(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, JsonNodePath instanceLocation, boolean shouldValidateSchema)
Description copied from interface:JsonValidator
This is default implementation of walk method. Its job is to call the validate method if shouldValidateSchema is enabled.- Parameters:
executionContext
- ExecutionContextnode
- JsonNoderootNode
- JsonNodeinstanceLocation
- JsonNodePathshouldValidateSchema
- boolean- Returns:
- a set of validation messages if shouldValidateSchema is true.
-
toString
public String toString()
END OF WALK METHODS- Overrides:
toString
in classBaseJsonValidator
-
hasTypeValidator
public boolean hasTypeValidator()
-
getTypeValidator
public TypeValidator getTypeValidator()
-
getValidators
public List<JsonValidator> getValidators()
-
initializeValidators
public void initializeValidators()
Initializes the validators'JsonSchema
instances. For avoiding issues with concurrency, in 1.0.49 theJsonSchema
instances affiliated with validators were modified to no more preload the schema and lazy loading is used instead.This comes with the issue that this way you cannot rely on validating important schema features, in particular
$ref
resolution at instantiation fromJsonSchemaFactory
.By calling
initializeValidators
you can enforce preloading of theJsonSchema
instances of the validators.
-
isRecursiveAnchor
public boolean isRecursiveAnchor()
-
createExecutionContext
public ExecutionContext createExecutionContext()
Creates an execution context.- Returns:
- the execution context
-
-