In this case, the annotation mechanism can be useful if, of course, you know what it is.
You can create your own annotation, for example:
@Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface MaxLength { int value(); }
And use it like:
@MaxLength(6) private String username;
Then you need to post-process such objects in a special post-processor, which you must create manually.
source share