Generated by GPT-5-mini| Bean Validation (JSR 380) | |
|---|---|
| Name | Bean Validation (JSR 380) |
| Title | Bean Validation (JSR 380) |
| Developer | Oracle Corporation / Eclipse Foundation |
| Released | 2017 |
| Latest | 2.0 |
| Language | Java |
| License | Apache License 2.0 |
Bean Validation (JSR 380) is a specification for declaring and validating constraints on Java object models using annotations and a programmatic API. It standardizes validation metadata for use with Jakarta EE, Java SE, Spring Framework, and other Eclipse Foundation-compatible platforms, enabling consistent constraint declaration, composition, and execution. The specification builds on prior Java standards and integrates with dependency injection, persistence, and web tiers across enterprise stacks such as Hibernate and GlassFish-based environments.
Bean Validation provides an annotation-driven model to assert invariants on properties, method parameters, and return values of Java beans. It defines a core API, a set of built-in constraint annotations, an extensible mechanism for custom constraints, and a validation engine contract implemented by vendors like Hibernate ORM, Apache Software Foundation, and commercial vendors operating in Oracle Corporation ecosystems. The API is designed to interoperate with standards such as Java Persistence API, Contexts and Dependency Injection and frameworks including Spring MVC, Jakarta RESTful Web Services, and JavaServer Faces.
The specification lineage begins with early validation efforts in the Java Community Process and formalizes with JSRs: predecessors include JSR 303 and JSR 349, culminating in JSR 380 published under the Java Specification Request system. Key contributors and organizations include experts from Hibernate, Red Hat, Oracle Corporation, and independent engineers active in standards bodies like the Eclipse Foundation Technical Committee. The evolution aligned with the transition from Oracle Corporation stewardship of Java EE to the Eclipse Foundation and the rebranding of Java EE to Jakarta EE.
Core elements include ConstraintDescriptor, ConstraintViolation, Validator, ValidatorFactory, and the Metadata API. The specification uses annotations such as @NotNull and constructs like ConstraintValidator to bind validation logic to types. Modeled for integration, the API supports programmatic bootstrapping, MessageInterpolator for localization compatible with formats used by Unicode Consortium standards, and TraversableResolver for determining reachability in object graphs. The contract provides for method-level validation inspired by AspectJ and interoperates with BeanManager contexts in environments like WildFly and GlassFish.
JSR 380 standardizes built-in annotations including @NotNull, @Size, @Min, @Max, @Pattern, @Email, and @PastOrPresent. It also defines grouping via interfaces enabling conditional execution of constraints using group sequences, a mechanism analogous to validation profiles used in enterprise projects such as OpenJDK-based builds and integration tests in JUnit and TestNG. Payload and composing constraints enable reuse patterns seen in frameworks like Spring Framework and persistence tools such as Hibernate ORM.
The specification defines how to author custom constraint annotations and implement ConstraintValidator instances that encapsulate validation logic. Custom validators can be registered via service loaders compatible with Java Platform Module System deployments and integrated into dependency injection contexts like CDI and Spring Boot. Constraint composition supports annotation-driven reuse and mirrors design practices familiar to developers working on libraries such as Apache Commons and application servers like Payara.
Implementations integrate with Jakarta Persistence lifecycle events to validate entities during persistence operations and with MVC frameworks like Spring MVC and Jakarta Faces for input validation. Containers such as WildFly, GlassFish, and WebLogic incorporate providers to enforce constraints at deployment time, while frameworks like Micronaut and Quarkus optimize runtime behavior for cloud-native environments. Integration points include method interception compatible with Interceptor specifications and exception handling patterns consistent with Servlet APIs.
Typical usage annotates DTOs, entities, and controller method parameters: for example, applying @NotNull, @Size, and @Email on form backing objects used by Spring MVC controllers and validated by Validator instances invoked from Servlet filters or programmatic bootstraps. Method validation enforces contracts on service interfaces implemented in containers like WildFly and tested with JUnit harnesses; validation groups allow phased checks in scenarios analogous to staged workflows in Apache Camel applications. Patterns include composing reusable annotation payloads, leveraging message interpolation for Unicode Consortium locales, and integrating with persistence callbacks in Hibernate ORM.
Major implementations include Hibernate ORM's Validator project, vendor integrations by Red Hat in WildFly, and community projects under the Apache Software Foundation umbrella. Compatibility matrices address Java SE versions, Jakarta EE migration paths from Oracle Corporation-era Java EE, and module system concerns introduced by OpenJDK initiatives. Implementations adhere to the specification contract while offering provider-specific extensions useful in cloud platforms like Amazon Web Services and Google Cloud Platform deployments.
Category:Java standards