我正在查看来自 github 的 2.2.6 版本的验证器代码。我没有更改回购“ https://github.com/fge/json-schema-validator.git ”中的任何代码
当我针对引用第二个模式文件的 json 模式进行测试时,我无法运行示例 1(当我使用硬编码的 URI 时,我可以让它工作)。
我只是简单地重新指出了“com.github.fge.jsonschema.examples.Example1.java”以使用我的团队 json 模式和 json 文件。我已经构建了项目并将我的 json 模式文件复制到“json-schema-validator\bin\com\github\fge\jsonschema\examples”(都在同一个文件夹中,类似于 fstab 示例)
附上一段顶层,
},
"MovingWindow": {
"description": "Is this an moving window measure?",
"type": "boolean"
}
},
"minItems": 1,
"uniqueItems": true
},
"RealTimeProfile": {
"$ref": "rtp.json#"
}
},
"required": [
"MeasureTemplateId",
"MeasureInstanceId",
但我无法读取较低级别的第二个模式文件(“rtp.json”)以被识别并正常工作。我看到以下错误:
线程“main”com.github.fge.jsonschema.core.exceptions.ProcessingException 中的异常:致命:URI“rtp.json#”不是绝对级别:“致命”uri:“rtp.json#”
我的代码片段:
File jsonFile = new File("CumulativeCountBad.json");
File jsonSchemaFile = new File("main.json");
JsonNode good = JsonLoader.fromFile(jsonFile);
JsonNode mainSchema = JsonLoader.fromFile(jsonSchemaFile);
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonSchema schema = factory.getJsonSchema(mainSchema);
ProcessingReport report;
report = schema.validate(good);
System.out.println("good: " + report);
我的问题似乎类似于以下问题,但是当我将引用设置为时,我似乎无法让事情运行:“$ref”:“rtp.json#”
https://github.com/fge/json-schema-validator/issues/94
任何帮助表示赞赏。PS - 我是一个java新手,如果有什么明显的东西我已经忽略了,我们深表歉意谢谢