2

我想验证我的 pojo 中的字符串列表(ccEmailAddresses)。我正在使用 Jsonschema2pojo 从 json 创建 Java pojo。

杰森-

{
"$schema": "http://json-schema.org/draft-03/schema",
"title": "Email Recipient",
"description": "Schema for an email recipient document.",
"type": "object",
"additionalProperties": false,
"required": true,
"properties": {
    "firstName": {
        "type": "string",
        "maxLength": 30
    },
    "lastName": {
        "type": "string",
        "minLength": 1,
        "maxLength": 50
    },
    "emailAddress": {
        "type": "string",
        "pattern": "|^[\\w-']+(?:[\\.\\+&=][\\w-']+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,10}$",
        "maxLength": 255,
        "required": true
    },
    "ccEmailAddresses": {
        "type": "array",
        "items": {
            "type" : "string",
            "pattern": "|^[\\w-']+(?:[\\.\\+&=][\\w-']+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,10}$"
            }
        }
    }
}

如上所述,模式不验证 ccEmailAddresses。但是它确实验证了电子邮件地址。因此,对于单个元素,它可以正常工作,但不适用于列表。

此外,我尝试将模式作为 -

{
"$schema": "http://json-schema.org/draft-03/schema",
"title": "Email Recipient",
"description": "Schema for an email recipient document.",
"type": "object",
"additionalProperties": false,
"required": true,
"properties": {
    "firstName": {
        "type": "string",
        "maxLength": 30
    },
    "lastName": {
        "type": "string",
        "minLength": 1,
        "maxLength": 50
    },
    "emailAddress": {
        "type": "string",
        "pattern": "|^[\\w-']+(?:[\\.\\+&=][\\w-']+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,10}$",
        "maxLength": 255,
        "required": true
    },
    "ccEmailAddresses": {
        "type": "array",
        "pattern": "|^[\\w-']+(?:[\\.\\+&=][\\w-']+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,10}$",
        "items": {
            "type" : "string"
        }
    }
}

}

即使这样也行不通。因此,我不希望从 Jsonschema2pojo 搬出。我找不到任何关于此的文档,但这一定是非常常见的用例。

任何帮助将不胜感激。

谢谢,

4

0 回答 0