我在我的json-schema中定义了我的自定义模式草案。
{ "$schema": "http://oag.company.com/ver1/schema#",
"title": "JSON Identity Attribute Schema"
}
字符串
并希望在代码验证中获取它。我使用com.networknt附带的 json-schema-validator-1.0.68.jar。我的代码
public static void main(String[] args) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
JsonSchemaFactory schemaFactory = JsonSchemaFactory.getInstance();
String exppath="exp.json";
String schpath ="schm.json";
try (
InputStream jsonStream = new FileInputStream(exppath);
InputStream schemaStream = new FileInputStream(schpath);
) {
JsonNode json = objectMapper.readTree(jsonStream);
com.networknt.schema.JsonSchema schema = schemaFactory.getSchema(schemaStream);
Set<ValidationMessage> validationResult = schema.validate(json);
if (validationResult.isEmpty()) {
System.out.println("no validation errors :-)");
System.out.println(json.path("FirstName"));
} else {
validationResult.forEach(vm -> System.out.println(vm));
}
}
}
型
我得到的错误消息是
线程“main”中出现异常com.networknt.schema.JsonSchemaException:未知MetaSchema:https://oag.oracle.com/ver1/schema
是thier任何方式,所以我可以使用我的自定义模式或我可以使用任何其他库,允许自定义模式?
1条答案
按热度按时间qybjjes11#
“$schema”是IETF标准的元版本,您需要将您的引用为“$ref”。
字符串