繁体   English   中英

JSON模式验证无法按预期的方式用于PropertyName

[英]JSON Schema Validation Not working as expected for PropertyName

我正在尝试JSON模式验证Ref: https : //wilddiary.com/validate-json-against-schema-in-java/

data.json在下面。 验证器根据模式检查并处理值类型。

但是,如果我尝试将属性名称ID更改为iddiff,则json仍然有效,尽管我期望出现无法识别的字段iddiff错误。 我也尝试其他图书馆。 有指针吗?

{
    "id": 1,
    "name": "A green door",
    "price": 12.50,
    "tags": ["home", "green"]
}

尝试以下链接。 此参考既简单又有用。 http://www.baeldung.com/introduction-to-json-schema-in-java

添加到您的架构:“ 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
}

Doc。 欲获得更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM