What's new in Bean Validation 2.0?
If you are already familiar with the bean validation API up to version 1.1, bean validation 2.0 comes with a set of new features that increases its maturity and compatibility with Java 8, and provides the missing features that were always requested and needed by Java developers. The bean validation specification states the following about the changes made in version 2.0:
"The main contribution of Bean Validation 2.0 is leveraging the new language features and API additions of Java 8 for the purposes of validation. Java 8 or later is required to use Bean Validation 2.0."
Some of the interesting changes include:
- New built-in constraints such as
@Email
,@NotEmpty
,@NotBlank
,@Positive
,@PositiveOrZero
,@Negative
,@NegativeOrZero
,@PastOrPresent
and@FutureOrPresent
, which make it more usable - Support for new date/time data types such as
@Past
and@Future
- Support for using repeatable annotations, introduced in Java 8, which makes its configuration much simpler