|
|
@ -20,7 +20,6 @@ import java.lang.annotation.Annotation; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.MethodParameter; |
|
|
|
import org.springframework.core.MethodParameter; |
|
|
|
import org.springframework.core.annotation.AnnotationUtils; |
|
|
|
|
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.messaging.Message; |
|
|
|
import org.springframework.messaging.Message; |
|
|
|
import org.springframework.messaging.converter.MessageConversionException; |
|
|
|
import org.springframework.messaging.converter.MessageConversionException; |
|
|
@ -38,12 +37,16 @@ import org.springframework.validation.BindingResult; |
|
|
|
import org.springframework.validation.ObjectError; |
|
|
|
import org.springframework.validation.ObjectError; |
|
|
|
import org.springframework.validation.SmartValidator; |
|
|
|
import org.springframework.validation.SmartValidator; |
|
|
|
import org.springframework.validation.Validator; |
|
|
|
import org.springframework.validation.Validator; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
import org.springframework.validation.annotation.ValidationAnnotationUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A resolver to extract and convert the payload of a message using a |
|
|
|
* A resolver to extract and convert the payload of a message using a |
|
|
|
* {@link MessageConverter}. It also validates the payload using a |
|
|
|
* {@link MessageConverter}. |
|
|
|
* {@link Validator} if the argument is annotated with a Validation annotation. |
|
|
|
* |
|
|
|
|
|
|
|
* <p>Validation is applied if the method argument is annotated with |
|
|
|
|
|
|
|
* {@link org.springframework.validation.annotation.Validated} or |
|
|
|
|
|
|
|
* {@code @jakarta.validation.Valid}. Validation failure results in an |
|
|
|
|
|
|
|
* {@link MethodArgumentNotValidException}. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>This {@link HandlerMethodArgumentResolver} should be ordered last as it |
|
|
|
* <p>This {@link HandlerMethodArgumentResolver} should be ordered last as it |
|
|
|
* supports all types and does not require the {@link Payload} annotation. |
|
|
|
* supports all types and does not require the {@link Payload} annotation. |
|
|
@ -196,8 +199,6 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Validate the payload if applicable. |
|
|
|
* Validate the payload if applicable. |
|
|
|
* <p>The default implementation checks for {@code @jakarta.validation.Valid}, |
|
|
|
|
|
|
|
* Spring's {@link Validated}, and custom annotations whose name starts with "Valid". |
|
|
|
|
|
|
|
* @param message the currently processed message |
|
|
|
* @param message the currently processed message |
|
|
|
* @param parameter the method parameter |
|
|
|
* @param parameter the method parameter |
|
|
|
* @param target the target payload object |
|
|
|
* @param target the target payload object |
|
|
@ -208,10 +209,8 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
for (Annotation ann : parameter.getParameterAnnotations()) { |
|
|
|
for (Annotation ann : parameter.getParameterAnnotations()) { |
|
|
|
Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class); |
|
|
|
Object[] validationHints = ValidationAnnotationUtils.determineValidationHints(ann); |
|
|
|
if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) { |
|
|
|
if (validationHints != null) { |
|
|
|
Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann)); |
|
|
|
|
|
|
|
Object[] validationHints = (hints instanceof Object[] objectHints ? objectHints : new Object[] {hints}); |
|
|
|
|
|
|
|
BeanPropertyBindingResult bindingResult = |
|
|
|
BeanPropertyBindingResult bindingResult = |
|
|
|
new BeanPropertyBindingResult(target, getParameterName(parameter)); |
|
|
|
new BeanPropertyBindingResult(target, getParameterName(parameter)); |
|
|
|
if (!ObjectUtils.isEmpty(validationHints) && this.validator instanceof SmartValidator sv) { |
|
|
|
if (!ObjectUtils.isEmpty(validationHints) && this.validator instanceof SmartValidator sv) { |
|
|
|