java json schema validation relative path not working (URI not found)

青春壹個敷衍的年華 提交于 2019-12-06 08:51:42

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());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!