經過一年的努力開發以及自上一次修訂之後的四年多時間,Bean Validation 2.0 (JSR 380) 的最終正式版終於發布了。
上周,JCP 執行委員會以 25 票贊成票一致通過了 JSR 的最終批准投票。投票結束後,就發布了 2.0.0 版本的規範、API 和 TCK。與此同時,參考 Bean Validation 最終版本的實現,Hibernate Validator 6 最終版也發布了。
接下來的幾天內,最終的規範將在 jcp.org 上的 JSR 380 頁面提供。
Bean Validation 2.0 的新特性概覽:
Support for validating container elements by annotating type arguments of parameterized types, e.g. List<@Positive Integer> positiveNumbers
; this also includes:
More flexible cascaded validation of collection types; e.g. values and keys of maps can be validated now: Map<@Valid CustomerType, @Valid Customer> customersByType
Support for java.util.Optional
Support for the property types declared by JavaFX
Support for custom container types by plugging in additional value extractors
Support for the JSR 310 date/time types for @Past
and @Future
; fine-grained control over the current time and time zone used for validation
New built-in constraints: @Email
, @NotEmpty
, @NotBlank
, @Positive
, @PositiveOrZero
, @Negative
, @NegativeOrZero
, @PastOrPresent
and @FutureOrPresent
All built-in constraints are marked as repeatable
Parameter names are retrieved using reflection
ConstraintValidator#initialize()
is a default method
Bean Validation 2.0 也將成為 Java EE 8 規範的一部分,它將在今年夏天發布。
來自:http://beanvalidation.org/