-
Notifications
You must be signed in to change notification settings - Fork 235
excluding fields
Mahmoud Ben Hassine edited this page Feb 29, 2016
·
11 revisions
You can exclude fields from being populated in two ways:
class Person {
private String name;
@Exclude
private int age;
}EnhancedRandom enhancedRandom = EnhancedRandomBuilder.aNewEnhancedRandomBuilder().build();
Person person = enhancedRandom.nextObject(Person.class, "age");
// or
EnhancedRandom enhancedRandom = EnhancedRandomBuilder.aNewEnhancedRandomBuilder()
.exclude(FieldDefinitionBuilder.field().named("age").ofType(Integer.class).inClass(Person.class).get())
.build();
Person person = enhancedRandom.nextObject(Person.class);
// or
EnhancedRandom enhancedRandom = EnhancedRandomBuilder.aNewEnhancedRandomBuilder()
.randomize(FieldDefinitionBuilder.field().named("age").ofType(Integer.class).inClass(Person.class).get(), new SkipRandomizer())
.build();
Person person = enhancedRandom.nextObject(Person.class);The second argument of the enhancedRandom.nextObject method is a var arg list of fields to exclude.
The SkipRandomizer is a typical implementation of the Null Object Pattern and allows you to skip fields from being populated.
Easy Random is created by Mahmoud Ben Hassine with the help of some awesome contributors!