我正在尝试json Schema验证Ref:https://wilddiary.com/validate-json-against-schema-in-java/
data.json在下面。 Validator根据模式检查并处理值类型。
但是,如果我尝试将propertyname id更改为iddiff,那么json仍然有效,尽管我期待一个无法识别的字段iddiff错误。我也尝试过其他库。有什么指针吗?
{
"id": 1,
"name": "A green door",
"price": 12.50,
"tags": ["home", "green"]
}
答案 0 :(得分:0)
请尝试以下链接。这个参考很简单,也很有帮助。 http://www.baeldung.com/introduction-to-json-schema-in-java
答案 1 :(得分:0)
添加到您的架构:“additionalProperties”:false
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "integer"
},
....
"minItems": 1,
"uniqueItems": true
}
},
"required": ["id", "name", "price"],
"additionalProperties": false
}