Bean Validation
| Company type | Specification |
|---|---|
| Industry | Software development |
| Founded | November 16, 2009 |
| Headquarters | Global |
| Products | Metadata framework and API for validation of JavaBean components |
| Parent | Java Community Process (JCP) |
| Website | beanvalidation |
Bean Validation establishes a metadata framework and an API designed for the validation of JavaBean components, primarily utilizing annotations as the main source of metadata, with the possibility to override settings through XML validation configuration files.
Originally integrated within Java EE, version 2 expanded its applicability to include Java SE environments.
The Java Bean Validation specification (JSR 303) received approval from the JCP on 16 November 2009 and was incorporated into the Java EE 6 platform. The Hibernate Validator, developed by the Hibernate team, serves as the official reference implementation and is responsible for producing the Bean Validation TCK, which all implementations conforming to JSR 303 are required to pass.
Current Version
The current iteration, Bean Validation 2.0, defined under JSR 380 and ratified in July 2017, mandates a minimum of Java 8. This version takes advantage of Java 8's features to improve validation functions, including:
- Validation of container elements using type-use annotations (for example, List<@Positive Integer> positiveNumbers), alongside broader cascaded validation support for collection types such as Map<@Valid CustomerType, @Valid Customer>
- Compatibility with java.util.Optional, JavaFX property types, and user-defined container types enabled by additional value extractors
- Advanced date/time constraints (@Past, @Future) allowing customization of the current time and timezone context
- Introduction of new built-in constraints: @Email, @NotEmpty, @NotBlank, @Positive, @PositiveOrZero, @Negative, @NegativeOrZero, @PastOrPresent, and @FutureOrPresent
- Repeatability support for all built-in constraints
- Capability to retrieve parameter names via reflection
- Default method implementations for ConstraintValidator#initialize()
- Revised XML namespace URLs for validation descriptor files
Previous Version
Released in May 2013, Bean Validation 1.1 (JSR 349) enhanced version 1.0 (JSR 303) by introducing:
- Validation mechanisms for method parameters and return values
- Integration with Dependency Injection frameworks
- A more transparent and open process for specification development
Further reading
- Open development process of JSR 303, 349, & 380
- Devoxx presentation: *Bean Validation 2.0 - you’ve put your annotations everywhere!* by Gunnar Morling
- Interview featuring Spec Lead Emmanuel Bernard
- Official JSR 303 page
- Hibernate Validator project page
- Documentation for Bean Validation TCK
- Instructions for executing the Bean Validation TCK