Java validation API: skip some rules without changing bean definition -
i have object in api jar, cannot change:
public class user { @notnull private string name; @notnull private string password; }
in code need use object , validate data inside, but, example, let password empty. cannot remove @notnull class (and cannot define groups given constraint). how can influence validation without redefinig scratch?
one possible solution override constraint definition of specific class using either constraint-mapping xml file or hibernate validator specific api.
as described in documentation, can overide specific annotations (like password field annotation) , leave others untouched.
<constraint-mappings ...> <bean class="user" ignore-annotations="false"> <field name="password" ignore-annotations="true"> ... new annotations </field> </bean> </constraint-mappings>
further reading:
Comments
Post a Comment