【发布时间】:2014-04-09 14:55:19
【问题描述】:
我们如何确保列表中的各个字符串不为空/空白或遵循特定模式
@NotNull
List<String> emailIds;
我也想加个图案
@Pattern("\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b.")
但我可以没有它。但我肯定希望有一个约束来检查列表中的任何字符串是否为空或空白。还有 Json 模式的样子
"ids": {
"description": "The ids associated with this.",
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"required" :true }
}
"required" :true does not seem to do the job
【问题讨论】:
-
为什么不创建一个对象而不是字符串,并在对象创建中强制执行模式。比如说,列出
eMailIds; Class EMailInfo (String emailid) .. 检查是否有效,如果错误则返回 null;并在该类中使用方法获取 emailIds -
创建一个 List 的派生类,它的 add() 方法覆盖所有这些?
标签: java json validation hibernate-validator jsr