如何使用json-schema-validator验证针对超模式的JSON

时间:2014-11-01 10:05:59

标签: java json validation jsonschema json-schema-validator

我无法弄清楚如何正确设置超级架构以使用json-schema-validator。我使用的是json-schema-validator的java版本,版本是2.2.5。

我的架构是:

{
"$schema": "http://json-schema.org/draftv4/hyper-schema#",
"title": "User object",
"description": "A user representation",
"type": "object",
"properties": {
    "email": {
        "description": "The user's email address",
        "format":"email",
        "maxLength": 255
    },
    "picture": {
        "description": "The user's picture",
        "type": "string",
        "media": {
            "binaryEncoding": "base64",
            "type": "image/png"
        }
    }
}
}

我的json对象是:

{"email":"k@w.de",
"picture":null}

现在,当我将架构加载到JsonSchemaFactory并打算开始验证时,我收到以下警告:

warning: the following keywords are unknown and will be ignored: [media]
level: "warning"
schema: {"loadingURI":"#","pointer":"/properties/picture"}
domain: "syntax"
ignored: ["media"]

除了$ schema字段之外,还有什么可以配置使用超级架构吗?

1 个答案:

答案 0 :(得分:0)

这是因为你的$ schema错了!

应该是http://json-schema.org/draft-04/hyper-schema#。有关众所周知的URI列表,请参阅section 6 of the core specification