Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional "groups" attribute to @Valid #269

Open
FabriSr opened this issue May 4, 2023 · 1 comment
Open

Add optional "groups" attribute to @Valid #269

FabriSr opened this issue May 4, 2023 · 1 comment

Comments

@FabriSr
Copy link

FabriSr commented May 4, 2023

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.

@blutorange
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants