Hi
To your first question we are indeed thinking about these kind of mutualization but they suffer several problems:
- you cannot adjust the parameter values (max in your example) between two different use of @SomeField
- you cannot change the message between two different use of @SomeField (arguably the most problematic of both problem)
I might have a solution for that but I have not explored it thoroughly yet.
Code:
@Retention(RUNTIME)
@Documented
@Length(min=10,max=20, message="blahblah")
@NotNull
public @interface SomeField {
@Convert(to="max", constraint=Length.class) int max();
@Convert(to="message", constraint=NotNull.class) String messageNotNull() default "notNull";
@Convert(to="message", constraint=Length.class) String messageLength() default "notNull";
}
But this approach also have limits:
- you can only define a conversion if an annotation is used once (@Patterns would not work for example)
I am happy to brainstorm from here.
One side question is why are you reusing someField? Shouldn't you mutualize it?
BTW you @ApplyConstraints annotation cannot compile.