Home > Software engineering >  org.everit.json.schema.SchemaException: #: could not determine version
org.everit.json.schema.SchemaException: #: could not determine version

Time:10-23

A SchemaException gets thrown saying the version could not be determined as the title says. The schema version is clearly in the schema. This is all before data validation. Any ideas why this error gets thrown?

My schema is as follows:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {},
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "randomString": {
        "type": "string"
      }
    }
  }
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

And Java code:

JSONParser jsonParser = new JSONParser();
                String schemaPath = new File("").getAbsolutePath()   schema.json;
                Object schemaObj = jsonParser.parse(new FileReader(schemaPath));
                org.json.simple.JSONObject schemaJson = (org.json.simple.JSONObject) schemaObj;
                JSONObject rawSchema = new JSONObject(schemaJson.toString());
                //This is where the SchemaException gets thrown, the line after this comment
                Schema schema = SchemaLoader.load(rawSchema);
                //schema.validate(json);
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

The library doesn't support draft 2020-12 and 2019-09.

You will have to use draft 7 for now (or use an other library).

Edit: the correct meta-schema URL for draft 7 is "$schema": "https://json-schema.org/draft-07/schema"

  • Related