Skip to content

bean validation support

Mahmoud Ben Hassine edited this page Jul 10, 2016 · 12 revisions

Bean Validation support

Random Beans can introspect fields annotated with Bean Validation API annotations and generate random values according to declared validation constraints. Let's see an example, here is a Person class:

public class Person {

    private String name;

    @javax.validation.constraints.Past
    private Date birthDate;

    // constructors, getters and setters omitted
}

If you populate a Person bean using Random Beans, the generated value for birthDate field will be a random date in the past. This feature allows you to generate valid random data according to constraints already defined on your beans.

Heads up! In order to activate Bean Validation support, you need to add the random-beans-validation dependency to your project:

<dependency>
   <groupId>io.github.benas</groupId>
   <artifactId>random-beans-validation</artifactId>
   <version>${latest.version}</version>
</dependency>

Note: Currently, Random Beans can generate random valid data for all Bean Validation API annotations except @Digits. Support for this annotation is planned for a future release.