我正在使用com.github.fge.jsonschema。使用Java。
以下是JSON模式。
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Employee",
"description": "employee description",
"type": "object",
"properties": {
"eid": {
"description": "The unique identifier for a emp",
"type": "integer"
},
"ename": {
"description": "Name of the emp",
"type": "string"
},
"qual":{
"$ref": "#/definitions/qualification"
}
},
"definitions": {
"qualification":
{
"description": "Qualification",
"type": "string"
}
}
}
这是用于验证架构的JSON。
{
"eid":1000,
"ename": "mrun",
"qualification": "BE"
}
问题是,如果我们传递任何错误的数据,它将正确验证eid和ename的类型(即整数或字符串)。例如:
{
"eid":"Mrun", //should be Integer
"ename": 72831287, //should be String
"qualification": 98372489 //should be String
}
如果仅通过错误的类型进行资格鉴定,则其验证为true(即,由于嵌套,它不对类型进行验证)。>>
需要对整个JSON执行验证。
还有其他解决方案来验证JSON中的嵌套对象吗?
提前感谢。
我正在使用com.github.fge.jsonschema。用Java工作。以下是JSON模式。 “ $ schema”:“ http://json-schema.org/draft-04/schema#”,“ title”:“ Employee”,“ description”:“ employee ...