Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright (c) 2012, Francis Galiegue <>
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the Lesser GNU General Public License as
  * published by the Free Software Foundation, either version 3 of the
  * License, or (at your option) any later version.
  * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * Lesser GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <>.
package com.github.fge.jsonschema.examples;
import static com.github.fge.jsonschema.main.JsonSchemaFactory.*;

Sixth example: URI redirection

link to source code

In this example, the same schema file is used as in Example1. This time, though, it is assumed that the base URI used for addressing this schema is But instead of trying to fetch it from the web directly, we want to use the local copy, which is located under URI resource:/org/eel/kitchen/jsonschema/examples/fstab.json#.

The solution is to use another method from com.github.fge.jsonschema.main.JsonSchemaFactory.Builder: com.github.fge.jsonschema.main.JsonSchemaFactory.Builder.addRedirection(java.lang.String,java.lang.String). This method can be called for as many schemas as you wish to redirect.

The effect is that if you required a schema via URI, it will silently transform this URI into resource:/org/eel/kitchen/jsonschema/examples/fstab.json# internally.

Note that URIs must be absolute JSON references (see com.github.fge.jsonschema.ref.JsonRef).

public final class Example6
    extends ExampleBase
    private static final String FROM = "";
    private static final String TO
        = "resource:/com/github/fge/jsonschema/examples/fstab.json#";
    public static void main(final String... args)
        throws IOExceptionJsonSchemaException
        final JsonNode good = loadResource("/fstab-good.json");
        final JsonNode bad = loadResource("/fstab-bad.json");
        final JsonNode bad2 = loadResource("/fstab-bad2.json");
        final JsonSchemaFactory factory = JsonSchemaFactory.builder()
        final JsonSchema schema = factory.fromURI();
        ValidationReport report;
        report = schema.validate(good);
        report = schema.validate(bad);
        report = schema.validate(bad2);
New to GrepCode? Check out our FAQ X