Bean Validation

Constrain once, validate everywhere

Latest news Stay up to date, subscribe to the news feed.

Bean Validation has a new website!

19 October 2017

Bean Validation just got a new website and we hope you will like it! New layout We developed a more modern layout based on Semantic UI. It should be easier to the eye...

Bean Validation 2.0 is a spec!

07 August 2017

It is done — after one year of hard work, and a bit more than four years after the previous revision, the final release of Bean Validation 2.0 (JSR 380) is out! Last week,...

Bean Validation 2.0 CR 3 released and submitted to Final Approval Ballot

12 July 2017

It’s my great pleasure to announce the CR 3 release of the Bean Validation 2.0 spec! This release of the spec and the API as well as accompanying releases of the...

What is Bean Validation

Bean Validation is a Java specification which

  • lets you express constraints on object models via annotations

  • lets you write custom constraints in an extensible way

  • provides the APIs to validate objects and object graphs

  • provides the APIs to validate parameters and return values of methods and constructors

  • reports the set of violations (localized)

  • runs on Java SE but is integrated in Java EE 6 and later; Bean Validation 2.0 is part of Java EE 8

public class User {

    private String email;

    @NotNull @Email
    public String getEmail() {
      return email;
    }

    public void setEmail(String email) {
      this.email = email;
    }
}

public class UserService {

  public void createUser(@Email String email,
                         @NotNull String name) {
    ...
  }
}

While you can run validation manually, it is more natural to let other specifications and frameworks validate data at the right time (user input in presentation frameworks, business service execution by CDI, entity insert or update by JPA).

In other words, run once, constrain anywhere.