Class FormatEvaluatorFactory

java.lang.Object
dev.harrel.jsonschema.FormatEvaluatorFactory
All Implemented Interfaces:
EvaluatorFactory

public final class FormatEvaluatorFactory extends Object implements EvaluatorFactory
EvaluatorFactory implementation that provides format validation capabilities. It should not be used as a standalone factory. It is intended to be used as a supplementary factory to a full dialect-compatible factory (like Draft2020EvaluatorFactory).
     new ValidatorFactory().withEvaluatorFactory(new FormatEvaluatorFactory());
 
May also be used in conjunction with custom factories:
     new ValidatorFactory().withEvaluatorFactory(EvaluatorFactory.compose(customFactory, new FormatEvaluatorFactory()));
 

It may not be fully compatible with JSON Schema specification. It is mostly based on tools already present in JDK itself. Supported formats:

  • date, date-time, time - uses DateTimeFormatter with standard ISO formatters,
  • duration - regex based validation as it may be combination of Duration and Period,
  • email, idn-email - uses JMail.isValid(String),
  • hostname - regex based validation,
  • idn-hostname - not supported - performs same validation as hostname,
  • ipv4, ipv6 - uses InternetProtocolAddress,
  • uri, uri-reference, iri, iri-reference - uses URI,
  • uuid - uses UUID,
  • uri-template - lenient checking of unclosed braces (should be compatible with Spring's implementation),
  • json-pointer, relative-json-pointer - manual validation,
  • regex - uses Pattern.
  • Constructor Details

    • FormatEvaluatorFactory

      public FormatEvaluatorFactory()
      Creates a default instance without vocabularies support.
    • FormatEvaluatorFactory

      public FormatEvaluatorFactory(Set<String> vocabularies)
      Creates a customized instance with vocabularies support. Validation will only be run when at least one of provided vocabularies is active during validation process.
  • Method Details

    • create

      public Optional<Evaluator> create(SchemaParsingContext ctx, String fieldName, JsonNode fieldNode)
      Description copied from interface: EvaluatorFactory
      This method will be invoked for each JSON object field during schema parsing process. Must not throw any exceptions.
      Specified by:
      create in interface EvaluatorFactory
      Parameters:
      ctx - current schema parsing context
      fieldName - field name (keyword) in JSON object for which Evaluator should be created
      fieldNode - value of field in JSON object
      Returns:
      If this factory supports given field name (keyword) it should return corresponding Evaluator wrapped in Optional, Optional.empty() otherwise.