我想在我的pojo中验证字符串列表(ccEmailAddresses)。我正在使用Jsonschema2pojo从json创建Java pojo。
Json -
{
"$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}$"
}
}
}
}
如上所述,pattern不验证ccEmailAddresses。但它确实验证了emailAddress。所以对于单个元素它只是工作正常但不是列表。
此外,我尝试将模式设为 -
{
"$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搬出去。 我找不到任何关于此的文档,但这必须是非常常见的用例。
任何帮助都将受到高度赞赏。
谢谢,