dev.harrel:json-schema Help

Format validation

By default, the format keyword performs no validation (only collects annotations as mandated by the JSON Schema specification). Format validation requires additional dependency:

<dependency> <groupId>com.sanctionco.jmail</groupId> <artifactId>jmail</artifactId> <version>2.0.2</version> </dependency>
implementation 'com.sanctionco.jmail:jmail:2.0.2'

To enable format validation, attach FormatEvaluatorFactory to your ValidatorFactory instance:

new ValidatorFactory().withEvaluatorFactory(new FormatEvaluatorFactory());

Supported formats

  • date, date-time, time - uses java.time.format.DateTimeFormatter with standard ISO formatters,

  • duration - uses regex validation as it may be a combination of java.time.Duration and java.time.Period,

  • email, idn-email - uses com.sanctionco.jmail.JMail,

  • hostname - uses regex validation,

  • idn-hostname - not supported - performs same validation as hostname,

  • ipv4, ipv6 - uses com.sanctionco.jmail.net.InternetProtocolAddress,

  • uri, uri-reference, iri, iri-reference - uses java.net.URI,

  • uuid - uses java.util.UUID,

  • uri-template - lenient checking of unclosed braces (compatible with Spring's implementation),

  • json-pointer, relative-json-pointer - uses manual validation,

  • regex - uses java.util.regex.Pattern.

Vocabulary compliance

Specification defines a way to turn on and off format validation using vocabularies, but due to it being cumbersome to use, it is not the default way to achieve this. This means, if you attach FormatEvaluatorFactory to your ValidatorFactory, it will validate formats regardless of the vocabularies' state.

If you still want to use vocabularies, you can use a special FormatEvaluatorFactory constructor, which accepts a set of strings (vocabulary names):

new FormatEvaluatorFactory(Set.of(Vocabulary.Draft2020.FORMAT_ASSERTION))

This will only enable format validation when Vocabulary.Draft2020.FORMAT_ASSERTION is enabled.

Adding custom formats

Adding custom formats is generally the same as adding custom keywords. See Custom keywords for more information. You can add new formats on top of the default ones by using EvaluatorFactory.compose or by composition and delegation to FormatEvaluatorFactory.

04 August 2025