I am looking at the 2.2.6 version of the validator code from github.
I have not changed any code from the repo "https://github.com/fge/json-schema-validator.git"
I am unable to get example 1 running when i test it against my json schema that references a second schema file (I can get it working when I resort to a hardcoded URI).
I have simply repointed the "com.github.fge.jsonschema.examples.Example1.java" to use my teams json schema and json files.
I have built the project and copied my json schema files into "json-schema-validator\bin\com\github\fge\jsonschema\examples" (All in the same folder, similar to fstab examples)
A section of the top level is attached,
"description": "Is this an moving window measure?",
File jsonFile = new File("CumulativeCountBad.json");
File jsonSchemaFile = new File("main.json");
JsonNode good = JsonLoader.fromFile(jsonFile);
JsonNode mainSchema = JsonLoader.fromFile(jsonSchemaFile);
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonSchema schema = factory.getJsonSchema(mainSchema);
report = schema.validate(good);
System.out.println("good: " + report);
The problem is that you load the JSON then turn it into a schema. And your schema does not have an absolute URI in "id". So, it cannot work.
You want to use an absolute URI to load them. Since you originally use a
File (note, with Java 7+ you really want to use java.nio.file instead), you can obtain an absolute URI to it with:
final File jsonSchemaFile = new File("main.json"); final URI uri = jsonSchemaFile.toURI();
You then load the schema with:
final JsonSchema schema = factory.getJsonSchema(uri.toString());