Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright (c) 2014, Francis Galiegue (
   * This software is dual-licensed under:
   * - the Lesser General Public License (LGPL) version 3.0 or, at your option, any
   *   later version;
   * - the Apache Software License (ASL) version 2.0.
  * The text of this file and of both licenses is available at the root of this
  * project or, if you have the jar distribution, in directory META-INF/, under
  * the names LGPL-3.0.txt and ASL-2.0.txt respectively.
  * Direct link to the sources:
  * - LGPL 3.0:
  * - ASL 2.0:
 package com.github.fge.jsonschema.processors.format;
 import java.util.List;
 import java.util.Map;

Format attribute handler

This processor is run after if and only if the user has chosen to perform format validation (it is enabled by default).

It will append a specific com.github.fge.jsonschema.keyword.validator.KeywordValidator to the list of already existing validators if and only if:

  • there is a format keyword in the current schema;
  • the specified format attribute is supported;
  • the instance type is supported by this format attribute.

Note that it will warn if the format attribute is not recognized.

 public final class FormatProcessor
     implements Processor<ValidatorListValidatorList>
     private final Map<StringFormatAttributeattributes;
     private final MessageBundle bundle;
     public FormatProcessor(final Library library,
         final ValidationConfiguration cfg)
          = library.getFormatAttributes().entries();
          = cfg.getValidationMessages();
          = dict.entries();
          = MessageBundles.getBundle(JsonSchemaValidationBundle.class);
     public ValidatorList process(final ProcessingReport report,
         final ValidatorList input)
         throws ProcessingException
         final SchemaContext context = input.getContext();
         final JsonNode node = context.getSchema().getNode().get("format");
         if (node == null)
             return input;
         final String fmt = node.textValue();
         final FormatAttribute attr = .get(fmt);
         if (attr == null) {
            return input;
        final NodeType type = context.getInstanceType();
        if (!attr.supportedTypes().contains(type))
            return input;
        final List<KeywordValidatorvalidators = Lists.newArrayList(input);
        return new ValidatorList(contextvalidators);
    private static KeywordValidator formatValidator(final FormatAttribute attr)
        return new KeywordValidator()
            public void validate(
                final Processor<FullDataFullDataprocessor,
                final ProcessingReport reportfinal MessageBundle bundle,
                final FullData data)
                throws ProcessingException
    public String toString()
        return "format attribute handler";
New to GrepCode? Check out our FAQ X