@Singleton @Primary @Requires(property="micronaut.validator.enabled", value="true", defaultValue="true") public class DefaultValidator extends java.lang.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(java.lang.Class<T> beanType,
java.lang.Object... arguments)
Create a new valid instance.
|
ExecutableMethodValidator |
forExecutables()
Overridden variation that returns a
ExecutableMethodValidator . |
protected BeanIntrospection<java.lang.Object> |
getBeanIntrospection(java.lang.Object object)
looks up a bean introspection for the given object.
|
protected BeanIntrospection<java.lang.Object> |
getBeanIntrospection(java.lang.Object object,
java.lang.Class<?> definedClass)
looks up a bean introspection for the given object by instance's class or defined class.
|
javax.validation.metadata.BeanDescriptor |
getConstraintsForClass(java.lang.Class<?> clazz) |
<T> T |
unwrap(java.lang.Class<T> type) |
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validate(BeanIntrospection<T> introspection,
T object,
java.lang.Class<?>... groups)
Validate the given introspection and object.
|
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validate(T object,
java.lang.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> java.util.concurrent.CompletionStage<T> |
validateCompletionStage(java.util.concurrent.CompletionStage<T> completionStage,
java.lang.Class<?>... groups)
Validate the given CompletionStage by returning a new CompletionStage that validates the emitted value.
|
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validateConstructorParameters(BeanIntrospection<? extends T> introspection,
java.lang.Object[] parameterValues,
java.lang.Class<?>... groups)
Validates parameters for the given introspection and values.
|
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validateConstructorParameters(java.lang.Class<? extends T> beanType,
Argument<?>[] constructorArguments,
java.lang.Object[] parameterValues,
java.lang.Class<?>[] groups)
Validates arguments for the given bean type and constructor arguments.
|
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validateConstructorParameters(java.lang.reflect.Constructor<? extends T> constructor,
java.lang.Object[] parameterValues,
java.lang.Class<?>... groups) |
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validateConstructorReturnValue(java.lang.reflect.Constructor<? extends T> constructor,
T createdObject,
java.lang.Class<?>... groups) |
java.util.Set<java.lang.String> |
validatedAnnotatedElement(AnnotatedElement element,
java.lang.Object value)
Validates an annotated element for the given value.
|
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validateParameters(T object,
ExecutableMethod method,
java.util.Collection<MutableArgumentValue<?>> argumentValues,
java.lang.Class<?>... groups)
Validate the parameter values of the given
ExecutableMethod . |
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validateParameters(T object,
ExecutableMethod method,
java.lang.Object[] parameterValues,
java.lang.Class<?>... groups)
Validate the parameter values of the given
ExecutableMethod . |
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validateParameters(T object,
java.lang.reflect.Method method,
java.lang.Object[] parameterValues,
java.lang.Class<?>... groups) |
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validateProperty(T object,
java.lang.String propertyName,
java.lang.Class<?>... groups) |
<T> org.reactivestreams.Publisher<T> |
validatePublisher(org.reactivestreams.Publisher<T> publisher,
java.lang.Class<?>... groups)
Validate the given publisher by returning a new Publisher that validates each emitted value.
|
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validateReturnValue(T object,
ExecutableMethod<?,java.lang.Object> executableMethod,
java.lang.Object returnValue,
java.lang.Class<?>... groups)
Validates the return value of a
ExecutableMethod . |
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validateReturnValue(T object,
java.lang.reflect.Method method,
java.lang.Object returnValue,
java.lang.Class<?>... groups) |
<T> java.util.Set<javax.validation.ConstraintViolation<T>> |
validateValue(java.lang.Class<T> beanType,
java.lang.String propertyName,
java.lang.Object value,
java.lang.Class<?>... groups) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getInstance
@Inject protected DefaultValidator(@NonNull ValidatorConfiguration configuration)
configuration
- The validator configuration@NonNull public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validate(@NonNull T object, @Nullable java.lang.Class<?>... groups)
validate
in interface javax.validation.Validator
@NonNull public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validate(@NonNull BeanIntrospection<T> introspection, @NonNull T object, @Nullable java.lang.Class<?>... groups)
T
- The object typeintrospection
- The introspectionobject
- The objectgroups
- The groups@NonNull public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateProperty(@NonNull T object, @NonNull java.lang.String propertyName, @Nullable java.lang.Class<?>... groups)
validateProperty
in interface javax.validation.Validator
@NonNull public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateValue(@NonNull java.lang.Class<T> beanType, @NonNull java.lang.String propertyName, @Nullable java.lang.Object value, @Nullable java.lang.Class<?>... groups)
validateValue
in interface javax.validation.Validator
@NonNull public java.util.Set<java.lang.String> validatedAnnotatedElement(@NonNull AnnotatedElement element, @Nullable java.lang.Object value)
AnnotatedElementValidator
validatedAnnotatedElement
in interface AnnotatedElementValidator
element
- The elementvalue
- The value@NonNull public <T> T createValid(@NonNull java.lang.Class<T> beanType, java.lang.Object... arguments) throws javax.validation.ConstraintViolationException
ExecutableMethodValidator
createValid
in interface ExecutableMethodValidator
T
- the generic typebeanType
- The typearguments
- The argumentsjavax.validation.ConstraintViolationException
- If a valid instance couldn't be constructedpublic javax.validation.metadata.BeanDescriptor getConstraintsForClass(java.lang.Class<?> clazz)
getConstraintsForClass
in interface javax.validation.Validator
public <T> T unwrap(java.lang.Class<T> type)
unwrap
in interface javax.validation.Validator
@NonNull public ExecutableMethodValidator forExecutables()
Validator
ExecutableMethodValidator
.forExecutables
in interface javax.validation.Validator
@NonNull public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateParameters(@NonNull T object, @NonNull ExecutableMethod method, @NonNull java.lang.Object[] parameterValues, @Nullable java.lang.Class<?>... groups)
ExecutableMethodValidator
ExecutableMethod
.validateParameters
in interface ExecutableMethodValidator
T
- The object typeobject
- The objectmethod
- The methodparameterValues
- The valuesgroups
- The groups@NonNull public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateParameters(@NonNull T object, @NonNull ExecutableMethod method, @NonNull java.util.Collection<MutableArgumentValue<?>> argumentValues, @Nullable java.lang.Class<?>... groups)
ExecutableMethodValidator
ExecutableMethod
.validateParameters
in interface ExecutableMethodValidator
T
- The object typeobject
- The objectmethod
- The methodargumentValues
- The valuesgroups
- The groups@NonNull public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateParameters(@NonNull T object, @NonNull java.lang.reflect.Method method, @NonNull java.lang.Object[] parameterValues, @Nullable java.lang.Class<?>... groups)
validateParameters
in interface ExecutableMethodValidator
validateParameters
in interface javax.validation.executable.ExecutableValidator
@NonNull public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateReturnValue(@NonNull T object, @NonNull java.lang.reflect.Method method, @Nullable java.lang.Object returnValue, @Nullable java.lang.Class<?>... groups)
validateReturnValue
in interface ExecutableMethodValidator
validateReturnValue
in interface javax.validation.executable.ExecutableValidator
@NonNull public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateReturnValue(@NonNull T object, @NonNull ExecutableMethod<?,java.lang.Object> executableMethod, @Nullable java.lang.Object returnValue, @Nullable java.lang.Class<?>... groups)
ExecutableMethodValidator
ExecutableMethod
.validateReturnValue
in interface ExecutableMethodValidator
T
- The object typeobject
- The objectexecutableMethod
- The methodreturnValue
- The return valuegroups
- The groups@NonNull public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateConstructorParameters(@NonNull java.lang.reflect.Constructor<? extends T> constructor, @NonNull java.lang.Object[] parameterValues, @Nullable java.lang.Class<?>... groups)
validateConstructorParameters
in interface ExecutableMethodValidator
validateConstructorParameters
in interface javax.validation.executable.ExecutableValidator
@NonNull public <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateConstructorParameters(@NonNull BeanIntrospection<? extends T> introspection, @NonNull java.lang.Object[] parameterValues, @Nullable java.lang.Class<?>... groups)
ExecutableMethodValidator
validateConstructorParameters
in interface ExecutableMethodValidator
T
- The bean type.introspection
- The introspectionparameterValues
- The parameter valuesgroups
- The groupspublic <T> java.util.Set<javax.validation.ConstraintViolation<T>> validateConstructorParameters(java.lang.Class<? extends T> beanType, Argument<?>[] constructorArguments, @NonNull java.lang.Object[] parameterValues, @Nullable java.lang.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> java.util.Set<javax.validation.ConstraintViolation<T>> validateConstructorReturnValue(@NonNull java.lang.reflect.Constructor<? extends T> constructor, @NonNull T createdObject, @Nullable java.lang.Class<?>... groups)
validateConstructorReturnValue
in interface ExecutableMethodValidator
validateConstructorReturnValue
in interface javax.validation.executable.ExecutableValidator
@Nullable protected BeanIntrospection<java.lang.Object> getBeanIntrospection(@NonNull java.lang.Object object, @NonNull java.lang.Class<?> definedClass)
object
- The object, never nulldefinedClass
- The defined class of the object, never null@Nullable protected BeanIntrospection<java.lang.Object> getBeanIntrospection(@NonNull java.lang.Object object)
object
- The object, never null@NonNull public <T> org.reactivestreams.Publisher<T> validatePublisher(@NonNull org.reactivestreams.Publisher<T> publisher, java.lang.Class<?>... groups)
ReactiveValidator
ConstraintViolationException
will be thrown.validatePublisher
in interface ReactiveValidator
T
- The generic typepublisher
- The publishergroups
- The groups@NonNull public <T> java.util.concurrent.CompletionStage<T> validateCompletionStage(@NonNull java.util.concurrent.CompletionStage<T> completionStage, java.lang.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