Package org.hibernate.validator.spi.cfg
Interface ConstraintMappingContributor
-
- All Known Implementing Classes:
ServiceLoaderBasedConstraintMappingContributor
public interface ConstraintMappingContributorImplementations contributeConstraintMappings to validator factory.A constraint mapping contributor can be configured in
META-INF/validation.xml, using the propertyBaseHibernateValidatorConfiguration.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:
BaseHibernateValidatorConfiguration.CONSTRAINT_MAPPING_CONTRIBUTORS
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceConstraintMappingContributor.ConstraintMappingBuilderA builder for adding constraint mappings.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcreateConstraintMappings(ConstraintMappingContributor.ConstraintMappingBuilder builder)Callback invoked during validator factory creation.
-
-
-
Method Detail
-
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
-
-