title: How to apply a sub schema in the JSON Schema validator?
body: <p>Hi I'm using the <a href="https://github.com/fge/json-schema-validator" rel="nofollow noreferrer">JSON Schema evaluator</a> in version 2.2.6 to validate my server responses. These responses can contain single objects of type A, B or C, but also composite objects, e.g., D containing an array of A objects. To reuse the schema definitions of each object, I started to describe all entities in the same file as described <a href="https://stackoverflow.com/questions/8179137/how-to-manage-multiple-json-schema-files">here</a>. Now my problem is, that I have to reference one of those single objects when validating the response.</p>
  
  <p>Here is my (not) SWE.</p>
  
  <p>JSON schema file:</p>
  
  <pre><code>{
      "id":"#root",
      "properties": {
          "objecta": {
              "type": "object",
              "id":"#objecta",
              "properties": {
                  "attribute1": {"type": "integer"},
                  "attribute2": {"type": "null"},
              },
              "required": ["attribute1", "attribute2"]
          },
          "objectb": {
              "type": "object",
              "id":"#objectb",
              "properties": {
                  "attribute1": {"type": "integer"},
                  "attribute2": {
                      "type": "array",
                          "items": {
                              "$ref": "#/objecta"
                          }
                      }
                  }
              },
              "required": ["attribute1", "attribute2"]
          },
      }
  }
  </code></pre>
  
  <p>Now I want to validate a server response containing object B. For this, I tried the following:</p>
  
  <pre><code>public class SchemeValidator {
  
      public static void main(String[] args) {
  
          String jsonData = pseudoCodeFileLoad("exampleresponse/objectb.txt");
          final File jsonSchemaFile = new File("resources/jsonschemes/completescheme.json");
          final URI uri = jsonSchemaFile.toURI();
  
          ProcessingReport report = null;
  
          try {
              JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
              final JsonSchema schema = factory.getJsonSchema(uri.toString() + "#objectb");
              JsonNode data = JsonLoader.fromString(jsonData);
              report = schema.validate(data);
          } catch (JsonParseException jpex) {
              // ... handle parsing errors etc.
          }
      }
  }
  </code></pre>
  
  <p>The problem is that the scheme is not loaded correctly. I either get no error (even for invalid responses) or I get <code>fatal: illegalJsonRef</code> as the scheme seems to be empty. How can I use the schema of object b in my Java code? Thank you!!</p>