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

Feature request: Type Level Annotations for ConstraintTarget #379

Open
jochenwierum opened this issue Apr 5, 2024 · 0 comments
Open

Feature request: Type Level Annotations for ConstraintTarget #379

jochenwierum opened this issue Apr 5, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@jochenwierum
Copy link

Most important: Thanks for this great library!

As already mentioned in #290, it would be very helpful to have an Annotation like ConstraintTarget on the type level. In my Opinion, the first snipped reduces the amount of boilerplate code, especially if you have (much) more than two properties:

@ConstraintTargets
class Person {
  private String firstname;
  private String firstname;

  public Person(String firstname, String lastname) {
    this.firstname = firstname;
    this.lastname = lastname;
  }

  String getFirstname() { return firstname; }
  String getLastname() { return lastname; }
}
class Person {
  private String firstname;
  private String firstname;

  public Person(String firstname, String lastname) {
    this.firstname = firstname;
    this.lastname = lastname;
  }

  @ConstraintTarget
  String getFirstname() { return firstname; }

  @ConstraintTarget
  String getLastname() { return lastname; }
}

I think we can assume that for a Variable T x there is either a getter T getX() or T x() (or T isX() if x is a boolean). More complex cases could be still written in the classic style by annotating each getter.

Also, this would be really great to work in combination with lombok, so we only would need to write:

@ConstraintTargets
@Value
class Person {
  String firstname;
  String firstname;
}

However, this might be a different problem, I guess.

@making making added the enhancement New feature or request label Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants