1

How can this interface be redesigned or wrapped by another interface so it can be applied (many times) but always with different value (not just 100) for the annotation: @MaxLength(X)

public interface FixedString{
    String getValue();
    void setValue(@NotNull @MaxLength(100) String value);
}

Your suggestions appreciated

Felix
  • 213
  • 2
  • 9

1 Answers1

0

Since annotation only accepts compile-time constants, I'll suggest the usage of cross field / class level validation by introducing a max length field and validating value length against it.

Some references:

How can I validate two or more fields in combination?

https://dwuysan.wordpress.com/2012/03/20/cross-field-validation-using-bean-validation-jsr-303/

Community
  • 1
  • 1
Samuel Kok
  • 585
  • 8
  • 16