JSR 380 Bean Validation 2.0 Features

Two important facts About JSR 380:

1. It is end-agnostic, meaning you can use it anywhere you like (front-end, back-end, even DTO if you follow this pattern)

2. Its reference implementation is Hibernate Validator(6.0.1+)

Bean Validation standardizes constraint definition, declaration, and validation for the Java platform. Its first two incarnations have been widely popular amongst the Java community in both, SE and EE environments. Integrations with many other specifications (CDI, JAX-RS, JPA, etc.) and frameworks have been created.

Since Bean Validation 1.1 (which addressed many feature requests created by the community), Java 8 has been released, adding several language improvements which are very useful for the purposes of Bean Validation. Therefore the work of the Expert Group will be primarily focused on embracing Java 8 features:

* Use type-use annotations to apply constraints to collection elements: List<@NotNull @Email String> emails;
* Mark the standardized constraints with @Repeatable eliminating the need for the explicit usage of the @Size.List pattern
* Support @Future/@Past for the types of the new time and date API (JSR 310)
* Retrieve parameter names via reflection to report parameter constraint violations
* Integrate with a new Optional wrapper type

Note, that in order to leverage these constructs, Bean Validation 2.0 will require Java 8 as the minimum Java version.

In addition to the Java 8 related changes, Bean Validation 2.0 will seek to address further feature requests and improvements raised by the community. Potential examples of such features are:

* Simpler constraint ordering on single properties
* Custom payload for constraint violations
* Separate the notion of message interpolation and retrieval of message bundles
* Clarification of ambiguities found in Bean Validation 1.1
* Alignment with the JDK 9 modular environment
* ConstraintViolationException builder
* Validate an object graph assuming a list of changes to be applied

Note that this list is not exhaustive but gives a good representation. Additional feature requests are available in Bean Validation’s issue tracker https://hibernate.atlassian.net/projects/BVAL. The goal of the Expert Group will be to assess these issues, prioritize them as well as identify and pursue directions for enhancement of the overall programming model and facilities of Bean Validation.

Prototypes and implementations for some of these features have been carried out by the Hibernate Validator community (RI). This will help to shape a high-quality standard thanks to the experience gained.


Bean Validation Specifications

Bean Validation 2.0

Bean Validation 2.0 (JSR 380) was finished in August 2017.

It’s part of Java EE 8 (but can be used with plain Java SE as the previous releases).

Bean Validation 1.1

Bean Validation 1.1 (JSR 349) was finished in 2013 and is part of Java EE 7. Its main contributions are method-level validation, integration with CDI, group conversion and some more.

Bean Validation 1.0

Bean Validation 1.0 (JSR 303) was the first version of Java’s standard for object validation. It was released in 2009 and is part of Java EE 6.