Add optional "groups" attribute to @Valid
At the moment, when using @Valid annotation, there is no way to specify which groups must be validated. Inspired by the Springs @Validated annotation, my suggestion is to add an optional attribute to @Valid annotation, "groups", where we can define which groups should be validated.
You mean that it lets us define which will be validated? E.g.
class User {
@Valid(group = Basic.class)
private Account account;
}
class Account {
@NotEmpty(group = Basic.class)
private String name;
@NotEmpty(group = Advanced.class)
private String details;
}
It would then validate the account field using the Basic group? That also sounds useful, but as mentioned in in #268, it would also be great if we could specify the groups that must be active for @Valid to be applied at all.
class User {
@NotEmpty
private String name;
@Valid(group = MustValidateAccount.class)
private Account account;
}
class Account {
@NotEmpty
private String name;
@NotEmpty
private String details;
}
This would only validate the account field when the user instance is validated with the MustValidateAccount group. For the first use case, I would prefer the name targetGroup instead of group.