From the course: Java EE: Bean Validation

Bean Validation implementations

From the course: Java EE: Bean Validation

Start my 1-month free trial

Bean Validation implementations

- [Instructor] The Bean Validation API that's packaged with the Java EE platform is contained in a top level package javax.validation. The various parts of the API are in subpackages. The entry point to the API is the javax.validation .validation interface which provides three ways to boost up the API. This is usually done behind the scenes so you don't need to worry about doing it yourself. And the most interesting package is the constraints package which is located underneath the javax.validation package. It is in this package that you will find all the built-in constraints such as the Email constraint, the NotNull constraint and so on. I'll be using all the constraints in this package throughout this course so you'll get to know them very well. The implementation that comes with the Java EE platform conforms strictly to the JSR specification and provides no more and no less than what the specification requires. The version I will be using in this course is version 2.0 which is packaged with Java EE 8. However another flavor of the Bean Validation API exists called Hibernate Validator. This is a very popular implementation of the JSR and provides more than the specification requires. It is referred to as the reference implementation which means that it guarantees to provide at least what the specification defines although it actually provides much more. Most notably, it provides more Bean Validation constraints that validate all kinds of data shapes such as credit card numbers, social security numbers, and bar codes. Later on in this course, you'll be getting to use some of these constraints. The top-level package is org.hibernate.validator and provides the bootstrapping capabilities of the API. The constraints are in the package constraints under the parent package and includes the 22 constraints detailed in the specification and 21 additional constraints. A version of the Hibernate Validator I'll be using in this course is version 6.0 because it aligns with the Bean Validation API version 2.0 and Java EE 8. Take a look at this table. It shows the alignment between Java EE, the Bean Validation API, the Hibernate Validator API, and the minimum version of Java SE you must have configured. As already mentioned, this course will use Java EE 8, Bean Validation 2.0 and Hibernate Validator 6. However if you are using Java EE 7 or 6, you will still get great value from this course. The only thing you will notice is that not all the constraints I mentioned are available in the versions you are using. Other than that, everything else is valid for whatever version you are using. The Java docs for the Bean Validation API can be found on the Java EE's GitHub account and the Java docs for the Hibernate Validator API can be found on the Hibernate website. For full information about the Hibernate Validate API, you should visit the URL hibernate.org/validator.

Contents