Search in sources :

Example 1 with AnnotatedElement

use of io.micronaut.core.annotation.AnnotatedElement in project micronaut-core by micronaut-projects.

the class DefaultValidator method validatePropertyInternal.

private <T> void validatePropertyInternal(@Nullable Class<T> rootBeanClass, @Nullable T rootBean, @Nullable Object object, @NonNull DefaultConstraintValidatorContext context, @NonNull Set<ConstraintViolation<Object>> overallViolations, @NonNull Class propertyType, @NonNull AnnotatedElement constrainedProperty, @Nullable Object propertyValue) {
    final AnnotationMetadata annotationMetadata = constrainedProperty.getAnnotationMetadata();
    final List<Class<? extends Annotation>> constraintTypes = annotationMetadata.getAnnotationTypesByStereotype(Constraint.class);
    for (Class<? extends Annotation> constraintType : constraintTypes) {
        ValueExtractor<Object> valueExtractor = null;
        if (propertyValue != null && !annotationMetadata.hasAnnotation(Valid.class)) {
            // noinspection unchecked
            valueExtractor = valueExtractorRegistry.findUnwrapValueExtractor((Class<Object>) propertyValue.getClass()).orElse(null);
        }
        if (valueExtractor != null) {
            valueExtractor.extractValues(propertyValue, (SimpleValueReceiver) (nodeName, extractedValue) -> valueConstraintOnProperty(rootBeanClass, rootBean, object, context, overallViolations, constrainedProperty, propertyType, extractedValue, constraintType));
        } else {
            valueConstraintOnProperty(rootBeanClass, rootBean, object, context, overallViolations, constrainedProperty, propertyType, propertyValue, constraintType);
        }
    }
}
Also used : Publishers(io.micronaut.core.async.publisher.Publishers) ArrayUtils(io.micronaut.core.util.ArrayUtils) ConstraintValidatorRegistry(io.micronaut.validation.validator.constraints.ConstraintValidatorRegistry) MessageSource(io.micronaut.context.MessageSource) ElementDescriptor(javax.validation.metadata.ElementDescriptor) Valid(javax.validation.Valid) ValueExtractor(javax.validation.valueextraction.ValueExtractor) BeanResolutionContext(io.micronaut.context.BeanResolutionContext) Path(javax.validation.Path) PropertyDescriptor(javax.validation.metadata.PropertyDescriptor) ArgumentUtils(io.micronaut.core.util.ArgumentUtils) ConstraintViolation(javax.validation.ConstraintViolation) Method(java.lang.reflect.Method) Property(io.micronaut.context.annotation.Property) ClassUtils(io.micronaut.core.reflect.ClassUtils) MutableArgumentValue(io.micronaut.core.type.MutableArgumentValue) MethodReference(io.micronaut.inject.MethodReference) Singleton(jakarta.inject.Singleton) ConstraintValidatorContext(io.micronaut.validation.validator.constraints.ConstraintValidatorContext) Collectors(java.util.stream.Collectors) Introspected(io.micronaut.core.annotation.Introspected) StringUtils(io.micronaut.core.util.StringUtils) CompletionStage(java.util.concurrent.CompletionStage) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) Annotation(java.lang.annotation.Annotation) Scope(javax.validation.metadata.Scope) BeanDescriptor(javax.validation.metadata.BeanDescriptor) BeanIntrospector(io.micronaut.core.beans.BeanIntrospector) InjectionPoint(io.micronaut.inject.InjectionPoint) ArgumentValue(io.micronaut.core.type.ArgumentValue) ConstraintDescriptor(javax.validation.metadata.ConstraintDescriptor) ClockProvider(javax.validation.ClockProvider) java.util(java.util) BeanProperty(io.micronaut.core.beans.BeanProperty) Constructor(java.lang.reflect.Constructor) Function(java.util.function.Function) ExecutableMethod(io.micronaut.inject.ExecutableMethod) BeanInstantiationException(io.micronaut.context.exceptions.BeanInstantiationException) SimpleValueReceiver(io.micronaut.validation.validator.extractors.SimpleValueReceiver) MethodType(javax.validation.metadata.MethodType) MethodDescriptor(javax.validation.metadata.MethodDescriptor) Primary(io.micronaut.context.annotation.Primary) ConstraintValidator(io.micronaut.validation.validator.constraints.ConstraintValidator) Nullable(io.micronaut.core.annotation.Nullable) Requires(io.micronaut.context.annotation.Requires) ReturnType(io.micronaut.core.type.ReturnType) ConfigurationReader(io.micronaut.context.annotation.ConfigurationReader) Argument(io.micronaut.core.type.Argument) AnnotatedElement(io.micronaut.core.annotation.AnnotatedElement) ValueExtractorRegistry(io.micronaut.validation.validator.extractors.ValueExtractorRegistry) Default(javax.validation.groups.Default) Publisher(org.reactivestreams.Publisher) BeanDefinitionValidator(io.micronaut.inject.validation.BeanDefinitionValidator) ConstructorDescriptor(javax.validation.metadata.ConstructorDescriptor) ElementType(java.lang.annotation.ElementType) TraversableResolver(javax.validation.TraversableResolver) NonNull(io.micronaut.core.annotation.NonNull) Flux(reactor.core.publisher.Flux) ExecutionHandleLocator(io.micronaut.context.ExecutionHandleLocator) ConstraintViolationException(javax.validation.ConstraintViolationException) Constraint(javax.validation.Constraint) ValidationException(javax.validation.ValidationException) CollectionUtils(io.micronaut.core.util.CollectionUtils) BeanIntrospection(io.micronaut.core.beans.BeanIntrospection) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) BeanDefinition(io.micronaut.inject.BeanDefinition) ElementKind(javax.validation.ElementKind) AnnotatedElementValidator(io.micronaut.inject.annotation.AnnotatedElementValidator) Intercepted(io.micronaut.aop.Intercepted) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) Annotation(java.lang.annotation.Annotation)

Aggregations

Intercepted (io.micronaut.aop.Intercepted)1 BeanResolutionContext (io.micronaut.context.BeanResolutionContext)1 ExecutionHandleLocator (io.micronaut.context.ExecutionHandleLocator)1 MessageSource (io.micronaut.context.MessageSource)1 ConfigurationReader (io.micronaut.context.annotation.ConfigurationReader)1 Primary (io.micronaut.context.annotation.Primary)1 Property (io.micronaut.context.annotation.Property)1 Requires (io.micronaut.context.annotation.Requires)1 BeanInstantiationException (io.micronaut.context.exceptions.BeanInstantiationException)1 AnnotatedElement (io.micronaut.core.annotation.AnnotatedElement)1 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)1 AnnotationValue (io.micronaut.core.annotation.AnnotationValue)1 Introspected (io.micronaut.core.annotation.Introspected)1 NonNull (io.micronaut.core.annotation.NonNull)1 Nullable (io.micronaut.core.annotation.Nullable)1 Publishers (io.micronaut.core.async.publisher.Publishers)1 BeanIntrospection (io.micronaut.core.beans.BeanIntrospection)1 BeanIntrospector (io.micronaut.core.beans.BeanIntrospector)1 BeanProperty (io.micronaut.core.beans.BeanProperty)1 ClassUtils (io.micronaut.core.reflect.ClassUtils)1