更新时间:2022-01-30 22:17:52
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.
您希望使用绝对URI来加载它们。由于您最初使用的是文件
(注意,使用Java 7+,您确实希望使用java.nio.file),您可以使用以下方法获取绝对URI: / p>
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();
然后加载架构:
final JsonSchema schema = factory.getJsonSchema(uri.toString());