Package org.hibernate.validator.spi.cfg
Interface ConstraintMappingContributor
public interface ConstraintMappingContributor
Implementations contribute
ConstraintMapping
s 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:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
A builder for adding constraint mappings. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Callback invoked during validator factory creation.
-
Method Details
-
createConstraintMappings
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
-