Skip to content

Customize Generators

The generated values can be adjusted using the following annotations.

If an annotation is written above the constructor, it is usually applied to all parameters within the constructor, should the parameter not have its own annotation.

@Use

With the Use Annotation a specific generator can be selected.

When @Use is applied to an array, the specified generator is applied to the individual values within the array.

(String) Name Generator

EEEE has a generator for (human) names: NameGenerator

@Generate
public MyClass(@Use(NameGenerator.class) final String name) {
    // could be James, Mary, John, ...
}

@Range

Limits the size of the generated value.

@Range({min, max, step})

Steps

For generators, a third argument can be used: the step. This specifies the steps in which the number is to be generated. This is very helpful with doubles, for example, to limit the precision.

public MyClass(
    @Range(0, 1, 0.2) final double value
) {
    // value could be 0, 0.2, 0.4, 0.6, 0.8, and 1
}

@Transform

Transforms a generated string. Same as the @Transform-annotation in the Validation section.


Last update: 2022-03-15