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:

http://docs.jboss.org/hibernate/validator/5.1/reference/en-us/html/chapter-xml-configuration.html#section-mapping-xml-constraints

http://docs.jboss.org/hibernate/validator/5.1/reference/en-us/html/validator-specifics.html#section-programmatic-api


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -