Closed
Description
It would be nice to be able to extend an existing validator to apply it on the root of the current validated object, in order to use a validator created for a super type (or just to create a hierarchy of validator)
For example, let's say I have two classes like these :
public class Person {
private String name;
public static final validator = ValidatorBuilder.of(Person.class)
.constraint(Person::getName, "name", Constraint::NotNull)
.build();
// Etc...
}
public class Employee extends Person {
private String serviceId;
public static final validator = ValidatorBuilder.of(Employee.class)
// Apply the validator Person.validator here
.constraint(Employee::getServiceId, "service", Constraint::NotNull)
.build();
// Etc ...
}
In this case, the work around I have come out with is .nest(Person.class::cast, "person", Person.validator)
but it's not super readable. and I end up with a prefix "person.Xxx" which doesn't really mean anything.
Something like .extends(Person.validator)
would be perfect