JSON模式验证重复的关键元素

时间:2016-06-17 08:46:43

标签: java json spring validation schema

我的架构;

{
"title": "Reporting Schema",
"type": "object", 
"properties":  {    
   "id" : {"type": "string", "minLength": 1, "maxLength":25 },
   "firstName" : {"type": "string", "minLength": 0, "maxLength":25 },
   "middleName" : {"type": "string", "minLength": 0, "maxLength":25 },
   "lastName" : {"type": "string", "minLength": 0, "maxLength":25 },
   "companyName" : {"type": "string", "minLength": 0, "maxLength":70 },
   "address1" : {"type": "string", "minLength": 0, "maxLength":50 },
   "address2" : {"type": "string", "minLength": 0, "maxLength":50 },
   "city" : {"type": "string", "minLength": 0, "maxLength":20 },
   "state" : {"type": "string", "minLength": 0, "maxLength":2 }
},
"required": [ "id"],
"additionalProperties": false
}

我要测试的数据;您可以看到它有多个firstName值。

{
"id" : "SchemaTest",

"firstName" : "D",
"firstName" : "D",
"firstName" : "D",

"middleName" : "M",
"lastName" : "Bro",
"companyName" : "",
"address1" : "Test_Address_One",
"address2" : "Test_Address_Two",
"city" : "City_Name",
"state" : "US"
}

是否可以让我的架构验证数据是否与架构合同相匹配并让它标记为错误验证?

我认为 addtionalProperties 部分中可能有一个选项。

0 个答案:

没有答案