@Singleton @Primary @Requires(property="micronaut.validator.enabled", value="true", defaultValue="true") public class DefaultValidator extends Object implements Validator, ExecutableMethodValidator, ReactiveValidator, AnnotatedElementValidator, BeanDefinitionValidator
Validator
interface.ANN_CONSTRAINT, ANN_VALID
DEFAULT
Modifier | Constructor and Description |
---|---|
protected |
DefaultValidator(ValidatorConfiguration configuration)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
createValid(Class<T> beanType,
Object... arguments)
Create a new valid instance.
|
ExecutableMethodValidator |
forExecutables()
Overridden variation that returns a
ExecutableMethodValidator . |
protected BeanIntrospection<Object> |
getBeanIntrospection(Object object)
looks up a bean introspection for the given object.
|
protected BeanIntrospection<Object> |
getBeanIntrospection(Object object,
Class<?> definedClass)
looks up a bean introspection for the given object by instance's class or defined class.
|
BeanDescriptor |
getConstraintsForClass(Class<?> clazz) |
<T> T |
unwrap(Class<T> type) |
<T> Set<ConstraintViolation<T>> |
validate(BeanIntrospection<T> introspection,
T object,
Class<?>... groups)
Validate the given introspection and object.
|
<T> Set<ConstraintViolation<T>> |
validate(T object,
Class<?>... groups) |
<T> void |
validateBean(BeanResolutionContext resolutionContext,
BeanDefinition<T> definition,
T bean)
Validates the given bean after it has been constructor.
|
<T> void |
validateBeanArgument(BeanResolutionContext resolutionContext,
InjectionPoint injectionPoint,
Argument<T> argument,
int index,
T value)
Validates the given bean after it has been constructor.
|
<T> CompletionStage<T> |
validateCompletionStage(CompletionStage<T> completionStage,
Class<?>... groups)
Validate the given CompletionStage by returning a new CompletionStage that validates the emitted value.
|
<T> Set<ConstraintViolation<T>> |
validateConstructorParameters(BeanIntrospection<? extends T> introspection,
Object[] parameterValues,
Class<?>... groups)
Validates parameters for the given introspection and values.
|
<T> Set<ConstraintViolation<T>> |
validateConstructorParameters(Class<? extends T> beanType,
Argument<?>[] constructorArguments,
Object[] parameterValues,
Class<?>[] groups)
Validates arguments for the given bean type and constructor arguments.
|
<T> Set<ConstraintViolation<T>> |
validateConstructorParameters(Constructor<? extends T> constructor,
Object[] parameterValues,
Class<?>... groups) |
<T> Set<ConstraintViolation<T>> |
validateConstructorReturnValue(Constructor<? extends T> constructor,
T createdObject,
Class<?>... groups) |
Set<String> |
validatedAnnotatedElement(AnnotatedElement element,
Object value)
Validates an annotated element for the given value.
|
<T> Set<ConstraintViolation<T>> |
validateParameters(T object,
ExecutableMethod method,
Collection<MutableArgumentValue<?>> argumentValues,
Class<?>... groups)
Validate the parameter values of the given
ExecutableMethod . |
<T> Set<ConstraintViolation<T>> |
validateParameters(T object,
ExecutableMethod method,
Object[] parameterValues,
Class<?>... groups)
Validate the parameter values of the given
ExecutableMethod . |
<T> Set<ConstraintViolation<T>> |
validateParameters(T object,
Method method,
Object[] parameterValues,
Class<?>... groups) |
<T> Set<ConstraintViolation<T>> |
validateProperty(T object,
String propertyName,
Class<?>... groups) |
<T> Publisher<T> |
validatePublisher(Publisher<T> publisher,
Class<?>... groups)
Validate the given publisher by returning a new Publisher that validates each emitted value.
|
<T> Set<ConstraintViolation<T>> |
validateReturnValue(T object,
ExecutableMethod<?,Object> executableMethod,
Object returnValue,
Class<?>... groups)
Validates the return value of a
ExecutableMethod . |
<T> Set<ConstraintViolation<T>> |
validateReturnValue(T object,
Method method,
Object returnValue,
Class<?>... groups) |
<T> Set<ConstraintViolation<T>> |
validateValue(Class<T> beanType,
String propertyName,
Object value,
Class<?>... groups) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getInstance
protected DefaultValidator(@NonNull ValidatorConfiguration configuration)
configuration
- The validator configuration@NonNull public <T> Set<ConstraintViolation<T>> validate(@NonNull T object, @Nullable Class<?>... groups)
@NonNull public <T> Set<ConstraintViolation<T>> validate(@NonNull BeanIntrospection<T> introspection, @NonNull T object, @Nullable Class<?>... groups)
T
- The object typeintrospection
- The introspectionobject
- The objectgroups
- The groups@NonNull public <T> Set<ConstraintViolation<T>> validateProperty(@NonNull T object, @NonNull String propertyName, @Nullable Class<?>... groups)
validateProperty
in interface Validator
@NonNull public <T> Set<ConstraintViolation<T>> validateValue(@NonNull Class<T> beanType, @NonNull String propertyName, @Nullable Object value, @Nullable Class<?>... groups)
validateValue
in interface Validator
@NonNull public Set<String> validatedAnnotatedElement(@NonNull AnnotatedElement element, @Nullable Object value)
AnnotatedElementValidator
validatedAnnotatedElement
in interface AnnotatedElementValidator
element
- The elementvalue
- The value@NonNull public <T> T createValid(@NonNull Class<T> beanType, Object... arguments) throws ConstraintViolationException
ExecutableMethodValidator
createValid
in interface ExecutableMethodValidator
T
- the generic typebeanType
- The typearguments
- The argumentsConstraintViolationException
- If a valid instance couldn't be constructedpublic BeanDescriptor getConstraintsForClass(Class<?> clazz)
getConstraintsForClass
in interface Validator
@NonNull public ExecutableMethodValidator forExecutables()
Validator
ExecutableMethodValidator
.forExecutables
in interface Validator
@NonNull public <T> Set<ConstraintViolation<T>> validateParameters(@NonNull T object, @NonNull ExecutableMethod method, @NonNull Object[] parameterValues, @Nullable Class<?>... groups)
ExecutableMethodValidator
ExecutableMethod
.validateParameters
in interface ExecutableMethodValidator
T
- The object typeobject
- The objectmethod
- The methodparameterValues
- The valuesgroups
- The groups@NonNull public <T> Set<ConstraintViolation<T>> validateParameters(@NonNull T object, @NonNull ExecutableMethod method, @NonNull Collection<MutableArgumentValue<?>> argumentValues, @Nullable Class<?>... groups)
ExecutableMethodValidator
ExecutableMethod
.validateParameters
in interface ExecutableMethodValidator
T
- The object typeobject
- The objectmethod
- The methodargumentValues
- The valuesgroups
- The groups@NonNull public <T> Set<ConstraintViolation<T>> validateParameters(@NonNull T object, @NonNull Method method, @NonNull Object[] parameterValues, @Nullable Class<?>... groups)
validateParameters
in interface ExecutableMethodValidator
validateParameters
in interface ExecutableValidator
@NonNull public <T> Set<ConstraintViolation<T>> validateReturnValue(@NonNull T object, @NonNull Method method, @Nullable Object returnValue, @Nullable Class<?>... groups)
validateReturnValue
in interface ExecutableMethodValidator
validateReturnValue
in interface ExecutableValidator
@NonNull public <T> Set<ConstraintViolation<T>> validateReturnValue(@NonNull T object, @NonNull ExecutableMethod<?,Object> executableMethod, @Nullable Object returnValue, @Nullable Class<?>... groups)
ExecutableMethodValidator
ExecutableMethod
.validateReturnValue
in interface ExecutableMethodValidator
T
- The object typeobject
- The objectexecutableMethod
- The methodreturnValue
- The return valuegroups
- The groups@NonNull public <T> Set<ConstraintViolation<T>> validateConstructorParameters(@NonNull Constructor<? extends T> constructor, @NonNull Object[] parameterValues, @Nullable Class<?>... groups)
validateConstructorParameters
in interface ExecutableMethodValidator
validateConstructorParameters
in interface ExecutableValidator
@NonNull public <T> Set<ConstraintViolation<T>> validateConstructorParameters(@NonNull BeanIntrospection<? extends T> introspection, @NonNull Object[] parameterValues, @Nullable Class<?>... groups)
ExecutableMethodValidator
validateConstructorParameters
in interface ExecutableMethodValidator
T
- The bean type.introspection
- The introspectionparameterValues
- The parameter valuesgroups
- The groupspublic <T> Set<ConstraintViolation<T>> validateConstructorParameters(Class<? extends T> beanType, Argument<?>[] constructorArguments, @NonNull Object[] parameterValues, @Nullable Class<?>[] groups)
ExecutableMethodValidator
validateConstructorParameters
in interface ExecutableMethodValidator
T
- The generic type of the beanbeanType
- The bean typeconstructorArguments
- The constructor argumentsparameterValues
- The parameter valuesgroups
- The validation groups@NonNull public <T> Set<ConstraintViolation<T>> validateConstructorReturnValue(@NonNull Constructor<? extends T> constructor, @NonNull T createdObject, @Nullable Class<?>... groups)
validateConstructorReturnValue
in interface ExecutableMethodValidator
validateConstructorReturnValue
in interface ExecutableValidator
@Nullable protected BeanIntrospection<Object> getBeanIntrospection(@NonNull Object object, @NonNull Class<?> definedClass)
object
- The object, never nulldefinedClass
- The defined class of the object, never null@Nullable protected BeanIntrospection<Object> getBeanIntrospection(@NonNull Object object)
object
- The object, never null@NonNull public <T> Publisher<T> validatePublisher(@NonNull Publisher<T> publisher, Class<?>... groups)
ReactiveValidator
ConstraintViolationException
will be thrown.validatePublisher
in interface ReactiveValidator
T
- The generic typepublisher
- The publishergroups
- The groups@NonNull public <T> CompletionStage<T> validateCompletionStage(@NonNull CompletionStage<T> completionStage, Class<?>... groups)
ReactiveValidator
ConstraintViolationException
will be thrown.validateCompletionStage
in interface ReactiveValidator
T
- The generic typecompletionStage
- The completion stagegroups
- The groupspublic <T> void validateBeanArgument(@NonNull BeanResolutionContext resolutionContext, @NonNull InjectionPoint injectionPoint, @NonNull Argument<T> argument, int index, @Nullable T value) throws BeanInstantiationException
BeanDefinitionValidator
validateBeanArgument
in interface BeanDefinitionValidator
T
- The bean typeresolutionContext
- The resolution contextinjectionPoint
- The injection pointargument
- The argumentindex
- The argument indexvalue
- The valueBeanInstantiationException
- if the bean is invalidpublic <T> void validateBean(@NonNull BeanResolutionContext resolutionContext, @NonNull BeanDefinition<T> definition, @NonNull T bean) throws BeanInstantiationException
BeanDefinitionValidator
validateBean
in interface BeanDefinitionValidator
T
- The bean typeresolutionContext
- The resolution contextdefinition
- The definitionbean
- The bean to validateBeanInstantiationException
- if the bean is invalid