Class EnumValidator
java.lang.Object
com.networknt.schema.ValidationMessageHandler
com.networknt.schema.BaseJsonValidator
com.networknt.schema.EnumValidator
- All Implemented Interfaces:
JsonValidator, JsonSchemaWalker
JsonValidator for enum.-
Nested Class Summary
Nested classes/interfaces inherited from class BaseJsonValidator
BaseJsonValidator.JsonNodePathJsonPath, BaseJsonValidator.JsonNodePathJsonPointer, BaseJsonValidator.JsonNodePathLegacy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stringprivate static final org.slf4j.Loggerprivate final Set<com.fasterxml.jackson.databind.JsonNode> Fields inherited from class BaseJsonValidator
schemaNode, suppressSubSchemaRetrieval, validationContextFields inherited from class ValidationMessageHandler
errorMessage, errorMessageKeyword, errorMessageType, evaluationParentSchema, evaluationPath, keyword, messageSource, parentSchema, schemaLocation -
Constructor Summary
ConstructorsConstructorDescriptionEnumValidator(SchemaLocation schemaLocation, JsonNodePath evaluationPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) -
Method Summary
Modifier and TypeMethodDescription(package private) static StringasText(com.fasterxml.jackson.databind.JsonNode node) protected booleanhasNumber(com.fasterxml.jackson.databind.node.ArrayNode node) Determines if the array node contains a number.private booleanisTypeLooseContainsInEnum(com.fasterxml.jackson.databind.JsonNode node) Check whether enum contains the value of the JsonNode if the typeLoose is enabled.protected com.fasterxml.jackson.databind.node.ArrayNodeprocessArrayNode(com.fasterxml.jackson.databind.node.ArrayNode node) Processes the array and ensures that numbers within have trailing zeroes stripped.protected com.fasterxml.jackson.databind.JsonNodeprocessNumberNode(com.fasterxml.jackson.databind.JsonNode n) Processes the number and ensures trailing zeros are stripped.validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, JsonNodePath instanceLocation) Validate the given JsonNode, the given node is the child node of the root node at given data path.Methods inherited from class BaseJsonValidator
atRoot, checkDiscriminatorMatch, collectAnnotations, collectAnnotations, debug, equals, fetchSubSchemaNode, getEvaluationParentSchema, getEvaluationPath, getKeyword, getNodeFieldType, getParentSchema, getSchemaLocation, getSchemaNode, hasAdjacentKeywordInEvaluationPath, message, preloadJsonSchemas, putAnnotation, registerAndMergeDiscriminator, toString, validateMethods inherited from class ValidationMessageHandler
getErrorMessage, getErrorMessageType, getMessageNodeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface JsonValidator
getEvaluationPath, getKeyword, getSchemaLocation, preloadJsonSchema, walk
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
nodes
-
error
-
-
Constructor Details
-
EnumValidator
public EnumValidator(SchemaLocation schemaLocation, JsonNodePath evaluationPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext)
-
-
Method Details
-
asText
-
validate
public Set<ValidationMessage> validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, JsonNodePath instanceLocation) Description copied from interface:JsonValidatorValidate the given JsonNode, the given node is the child node of the root node at given data path.- Specified by:
validatein interfaceJsonValidator- Parameters:
executionContext- ExecutionContextnode- JsonNoderootNode- JsonNodeinstanceLocation- JsonNodePath- Returns:
- A list of ValidationMessage if there is any validation error, or an empty list if there is no error.
-
isTypeLooseContainsInEnum
private boolean isTypeLooseContainsInEnum(com.fasterxml.jackson.databind.JsonNode node) Check whether enum contains the value of the JsonNode if the typeLoose is enabled.- Parameters:
node- JsonNode to check
-
processNumberNode
protected com.fasterxml.jackson.databind.JsonNode processNumberNode(com.fasterxml.jackson.databind.JsonNode n) Processes the number and ensures trailing zeros are stripped.- Parameters:
n- the node- Returns:
- the node
-
processArrayNode
protected com.fasterxml.jackson.databind.node.ArrayNode processArrayNode(com.fasterxml.jackson.databind.node.ArrayNode node) Processes the array and ensures that numbers within have trailing zeroes stripped.- Parameters:
node- the node- Returns:
- the node
-
hasNumber
protected boolean hasNumber(com.fasterxml.jackson.databind.node.ArrayNode node) Determines if the array node contains a number.- Parameters:
node- the node- Returns:
- the node
-