Bean Validation

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 in Java SE but is integrated in Java EE (6 and 7)
public class User {
    @NotNull @Email 
    public String getEmail() { return email; }
    public void setEmail(String email) { 
      this.email = email; 
    }
    private String 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.

Learn more and get the specification...

Feed Latest news

Stay up to date, subscribe to the news feed.

Bean Validation TCKs now with signature files for Java SE 8

18 June 2014

Good news for those of you who want to certify the compatibility of a Bean Validation implementation (and its API JAR) against Java SE 8. We have released updates to the Bean Validation TCK 1.0 and 1.1; The versions are 1.0.7.GA and 1.1.3.Final, respectively. Both TCK releases come now with a version of the...

Training materials on Bean Validation 1.1

28 May 2014

I have two good Bean Validation related content for you today. Training slides (in French) Laurent Guerin wrote a comprehensive training on Bean Validation (1.0 and 1.1) for French students. The slides are available under a Creative Commons license. I did review them and they are very good. The bad news is that they are...

XML namespace and JCP

04 June 2013

Antonio Goncalves, fellow JCP member and friend has asked me why Bean Validation XML's namespace has not moved from its original location to the jcp.org location like other Java EE 7 specifications. I don't remember being aware that such a move was orchestrated so there are two possible reasons: I was never been made aware of...