Interface ConstraintMappingContributor


public interface ConstraintMappingContributor
Implementations contribute ConstraintMappings to validator factory.

A constraint mapping contributor can be configured in META-INF/validation.xml, using the property BaseHibernateValidatorConfiguration.CONSTRAINT_MAPPING_CONTRIBUTORS, thus allowing to set up constraints to be validated by default validators dynamically via the API for programmatic constraint declaration.

Implementations must have a no-args constructor.

One or more mappings can be added as shown in the following:

 
 public static class MyConstraintMappingContributor implements ConstraintMappingContributor {

     public void createConstraintMappings(ConstraintMappingBuilder builder) {
         builder.addConstraintMapping()
             .type( Marathon.class )
                 .property( "name", METHOD )
                     .constraint( new NotNullDef() )
                 .property( "numberOfHelpers", FIELD )
                     .constraint( new MinDef().value( 1 ) );

         builder.addConstraintMapping()
             .type( Runner.class )
                 .property( "paidEntryFee", FIELD )
                     .constraint( new AssertTrueDef() );
     }
 }
 
 
Author:
Gunnar Morling
See Also:
  • Method Details

    • createConstraintMappings

      void createConstraintMappings(ConstraintMappingContributor.ConstraintMappingBuilder builder)
      Callback invoked during validator factory creation. Any constraint mapping configured via the passed builder will be added to the mappings of the factory.
      Parameters:
      builder - A builder for adding one or more constraint mappings