Class 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:

    • Duration accepts fractional seconds; RFC 3339 does not
    • Period does not accept a time component while RFC 3339 accepts both a date and time component
    • Duration accepts days but not years, months or weeks
    • 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: JsonValidator
        Validate the given JsonNode, the given node is the child node of the root node at given data path.
        Parameters:
        node - JsonNode
        rootNode - JsonNode
        at - String
        Returns:
        A list of ValidationMessage if there is any validation error, or an empty list if there is no error.