Package com.networknt.schema.format
Class DurationValidator
- java.lang.Object
-
- com.networknt.schema.BaseJsonValidator
-
- com.networknt.schema.format.DurationValidator
-
- All Implemented Interfaces:
JsonValidator,JsonSchemaWalker
public class DurationValidator extends BaseJsonValidator
Validates that a string property conforms to RFC 3339's understanding of duration as defined in ISO 8601:1988. This understanding is captured in appendix A of RFC 3339.This validator will enforce the strict definition of RFC 3339 unless
SchemaValidatorsConfig.isStrict()return false.JSON Schema Draft 2019-09 and later uses RFC 3339 to define dates and times. RFC 3339 bases its definition of duration of what is in the 1988 version of ISO 1801, which is over 35 years old and has undergone many changes with updates in 1991, 2000, 2004, 2019 and an amendment in 2022.
There are notable differences between the current version of ISO 8601 and RFC 3339:
- ISO 8601-2:2019 permits negative durations
- ISO 8601-2:2019 permits combining weeks with other terms (e.g. P1Y13W)
There are notable differences in how RFC 3339 defines a duration compared with how the Java Date/Time API defines it:
-
-
Field Summary
-
Fields inherited from class com.networknt.schema.BaseJsonValidator
applyDefaultsStrategy, failFast, parentSchema, schemaNode, schemaPath, validationContext
-
-
Constructor Summary
Constructors Constructor Description DurationValidator(String schemaPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext, String formatName, ValidatorTypeCode type)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<ValidationMessage>validate(com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, String at)Validate the given JsonNode, the given node is the child node of the root node at given data path.-
Methods inherited from class com.networknt.schema.BaseJsonValidator
atPath, atPath, atRoot, buildValidationMessage, checkDiscriminatorMatch, constructValidationMessage, debug, equals, fetchSubSchemaNode, getNodeFieldType, getParentSchema, getPathType, getSchemaNode, getSchemaPath, getValidatorType, greaterThan, isPartOfOneOfMultipleType, lessThan, parseErrorCode, preloadJsonSchemas, registerAndMergeDiscriminator, validate, walk
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.networknt.schema.JsonValidator
preloadJsonSchema
-
-
-
-
Constructor Detail
-
DurationValidator
public DurationValidator(String schemaPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext, String formatName, ValidatorTypeCode type)
-
-
Method Detail
-
validate
public Set<ValidationMessage> validate(com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, String at)
Description copied from interface:JsonValidatorValidate the given JsonNode, the given node is the child node of the root node at given data path.- Parameters:
node- JsonNoderootNode- JsonNodeat- String- Returns:
- A list of ValidationMessage if there is any validation error, or an empty list if there is no error.
-
-