Hibernate Validator 6 将成为 Bean Validation 2.0 的参考实现。此 Beta1 版本与 Bean Validation 规范的 2.0.0.Beta1 发布(公开审查草案)协调一致。
它还是一个用于验证 Bean Validation 规范未来增强的游乐场,因此欢迎对这里提出的内容提供反馈!
请注意,Hibernate Validator 6 需要 JDK 8 或更高版本。
自 Alpha2 以来的新内容
Bean Validation 2.0.0.Beta1 支持
此版本的主要目标是升级到 Bean Validation 2.0.0.Beta1。
这主要是对规范最新变更的小幅调整,但我们还增加了一些与容器元素验证相关的功能(例如 List<@NotBlank String>
)。
Metadata API 对容器元素约束的支持
到目前为止,容器元素约束尚未通过元数据 API 暴露。您现在可以通过 API 获取它们。
// Given a class User with a property declared as Map<@Valid AddressType, @NotNull Address> addresses
PropertyDescriptor propertyDescriptor = validator
.getConstraintsForClass( User.class )
.getConstraintsForProperty( "addresses" );
List<ContainerElementTypeDescriptor> containerElementTypeDescriptors =
propertyDescriptor.getContainerElementTypes();
ContainerElementTypeDescriptor mapKeyDescriptor = containerElementTypeDescriptors.get( 0 );
ContainerElementTypeDescriptor mapValueDescriptor = containerElementTypeDescriptors.get( 1 );
// get the type argument index corresponding to this container element
assert mapKeyDescriptor.getTypeArgumentIndex() == 0;
assert mapValueDescriptor.getTypeArgumentIndex() == 1;
// get the constraint descriptors for this container element
assert mapKeyDescriptor.getConstraintDescriptors().size() == 0;
assert mapValueDescriptor.getConstraintDescriptors().size() == 1;
// indicates if the validation is cascaded
assert mapKeyDescriptor.isCascaded() == true;
assert mapValueDescriptor.isCascaded() == false;
// get the potential nested container elements
assert mapKeyDescriptor.getContainerElementTypes().size() == 0;
assert mapValueDescriptor.getContainerElementTypes().size() == 0;
对新的内置注释的完善支持
对于新的内置注释,错误消息缺失,我们已修复此问题。请注意,一些翻译需要更新,因此如果您说英语、德语、法语或乌克兰语以外的语言,请毫不犹豫地 站出来 并发送一个 pull request。
我们还添加了对 JavaMoney 类型中的 @Positive
和 @Negative
的支持。
最后,我们为这些新约束添加了对 注解处理器 的支持。
以及其他一些内容
-
@SafeHtml
现在支持相对URL,多亏了新的baseURI
属性。 -
我们对一些内容进行了修复,以支持最新的 JDK 9 早期访问版本。
23个已修复问题的完整列表可以在 发布说明 中找到。
获取 6.0.0.Beta1
要使用 Maven、Gradle 等获取发布版本,请使用 GAV 坐标 org.hibernate.validator:{hibernate-validator|hibernate-validator-cdi|hibernate-validator-annotation-processor}:6.0.0.Beta1。请注意,组 ID 从 org.hibernate
(Hibernate Validator 5 及更早版本)更改为 org.hibernate.validator
(从 Hibernate Validator 6 开始)。
反馈、问题、想法?
要取得联系,请使用常规渠道
-
用户论坛(使用问题、一般反馈)
-
问题跟踪器(错误报告、功能请求)
-
邮件列表(与开发相关的讨论)
-
Bean Validation 开发邮件列表(关于 Bean Validation 规范的讨论)