java - How to impose common constraint on class with javax.validation library? -
i using bean validation constraints validate class instances @ run time. have many dtos each has multiple fields common constraint. want add constraint class applies properties of class. (as lombok @notnull constraint).
e.g
class person { @notnull private string name; @notnull private string address; @notnull private string contact; }
i want make this.
@notnull class person { private string name; private string address; private string contact }
you cannot plain bean validation. adding @notnull
class won't work.
one potential approach utilize xml configuration. idea have own annotation mynotnull
. framework need scan these annotations , build programmatic configuration class in question. example done via annotation processor during compile time. once have constraint mapping xml files add them jar , reference them in validation.xml. that's basic idea. personally, not sure whether worth effort.
Comments
Post a Comment