json-schema-validator
json-schema-validator copied to clipboard
Incorrect error description (NullPointerException) when using a non-uri value in the id field
Description
Insufficiently clear description of the error when using a non-uri value in the id field at the root of the schema element. It would be better to show a competent message about incorrect format
Repeating
{
"id": "JustSomeStringValue",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"field1":{
"type": "string"
}
}
}
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);
InputStream is = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("test.json");
JsonSchema node = factory.getSchema(is);```
output

@AntonovDmitriy Thanks for raising it. I am wondering if you could submit a PR to get it fixed.
Also, $id is not required to be a fully qualified URL. At the Wikimedia Foundation we use relative path URIs for $ids and provide base URIs when resolving them.
I just tried to use this library but realized I can't because our relative path $ids (e.g. "/entity/event/1.0.0") cause a similar exception. I think more recent versions have this NPE caught. The exception I get is:
com.networknt.schema.JsonSchemaException: /test/event/1.0.0: null is an invalid segment for URI {2}
Not to necrobump this, but I'm running into this exact issue. Our schema still loads, but it's still throwing the error in logs. Any work around?