Class DefaultConstraintValidators
java.lang.Object
io.micronaut.validation.validator.constraints.DefaultConstraintValidators
- All Implemented Interfaces:
ConstraintValidatorRegistry
@Singleton
@Introspected
public class DefaultConstraintValidators
extends Object
implements ConstraintValidatorRegistry
A factory bean that contains implementation for many of the default validations.
This approach is preferred as it generates fewer classes and smaller byte code than defining a
validator class for each case.
- Since:
- 1.2
- Author:
- graemerocher
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
Key for caching validators. -
Constructor Summary
ConstructorDescriptionDefault constructor.DefaultConstraintValidators
(@Nullable io.micronaut.context.BeanContext beanContext) Constructor used for DI. -
Method Summary
Modifier and TypeMethodDescription<A extends Annotation,
T>
@NonNull Optional<ConstraintValidator<A,T>> findConstraintValidator
(@NonNull Class<A> constraintType, @NonNull Class<T> targetType) Finds a constraint validator for the given type and target type.protected <A extends Annotation,
T>
Optional<ConstraintValidator<A,T>> findLocalConstraintValidator
(@NonNull Class<A> constraintType, @NonNull Class<T> targetType) Last chance resolve for constraint validator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.validation.validator.constraints.ConstraintValidatorRegistry
getConstraintValidator
-
Constructor Details
-
DefaultConstraintValidators
public DefaultConstraintValidators()Default constructor. -
DefaultConstraintValidators
@Inject public DefaultConstraintValidators(@Nullable @Nullable io.micronaut.context.BeanContext beanContext) Constructor used for DI.- Parameters:
beanContext
- The bean context
-
-
Method Details
-
findConstraintValidator
@NonNull public <A extends Annotation,T> @NonNull Optional<ConstraintValidator<A,T>> findConstraintValidator(@NonNull @NonNull Class<A> constraintType, @NonNull @NonNull Class<T> targetType) Description copied from interface:ConstraintValidatorRegistry
Finds a constraint validator for the given type and target type.- Specified by:
findConstraintValidator
in interfaceConstraintValidatorRegistry
- Type Parameters:
A
- The annotation typeT
- The target type- Parameters:
constraintType
- The annotation type of the constraint.targetType
- The type being validated.- Returns:
- The validator
-
findLocalConstraintValidator
protected <A extends Annotation,T> Optional<ConstraintValidator<A,T>> findLocalConstraintValidator(@NonNull @NonNull Class<A> constraintType, @NonNull @NonNull Class<T> targetType) Last chance resolve for constraint validator.- Type Parameters:
A
- The annotation typeT
- The target type- Parameters:
constraintType
- The constraint typetargetType
- The target type- Returns:
- The validator if present
-