public class PayloadMethodArgumentResolver extends Object implements HandlerMethodArgumentResolver
MessageConverter. It also validates the payload using a
Validator if the argument is annotated with a Validation annotation.
This HandlerMethodArgumentResolver should be ordered last as it
supports all types and does not require the Payload annotation.
| Constructor and Description |
|---|
PayloadMethodArgumentResolver(MessageConverter messageConverter)
Create a new
PayloadArgumentResolver with the given
MessageConverter. |
PayloadMethodArgumentResolver(MessageConverter messageConverter,
Validator validator)
|
PayloadMethodArgumentResolver(MessageConverter messageConverter,
Validator validator,
boolean useDefaultResolution)
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
isEmptyPayload(Object payload)
Specify if the given
payload is empty. |
Object |
resolveArgument(MethodParameter parameter,
Message<?> message)
Resolves a method parameter into an argument value from a given message.
|
protected Class<?> |
resolveTargetClass(MethodParameter parameter,
Message<?> message)
Resolve the target class to convert the payload to.
|
boolean |
supportsParameter(MethodParameter parameter)
Whether the given method parameter is
supported by this resolver.
|
protected void |
validate(Message<?> message,
MethodParameter parameter,
Object target)
Validate the payload if applicable.
|
public PayloadMethodArgumentResolver(MessageConverter messageConverter)
PayloadArgumentResolver with the given
MessageConverter.messageConverter - the MessageConverter to use (required)public PayloadMethodArgumentResolver(MessageConverter messageConverter, @Nullable Validator validator)
messageConverter - the MessageConverter to use (required)validator - the Validator to use (optional)public PayloadMethodArgumentResolver(MessageConverter messageConverter, @Nullable Validator validator, boolean useDefaultResolution)
messageConverter - the MessageConverter to use (required)validator - the Validator to use (optional)useDefaultResolution - if "true" (the default) this resolver supports
all parameters; if "false" then only arguments with the @Payload
annotation are supported.public boolean supportsParameter(MethodParameter parameter)
HandlerMethodArgumentResolversupportsParameter in interface HandlerMethodArgumentResolverparameter - the method parameter to checktrue if this resolver supports the supplied parameter;
false otherwise@Nullable public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception
HandlerMethodArgumentResolverresolveArgument in interface HandlerMethodArgumentResolverparameter - the method parameter to resolve.
This parameter must have previously been passed to
HandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)
which must have returned true.message - the currently processed messagenullException - in case of errors with the preparation of argument valuesprotected boolean isEmptyPayload(@Nullable Object payload)
payload is empty.payload - the payload to check (can be null)protected Class<?> resolveTargetClass(MethodParameter parameter, Message<?> message)
By default this is simply MethodParameter.getParameterType()
but that can be overridden to select a more specific target type after
also taking into account the "Content-Type", e.g. return String
if target type is Object and "Content-Type:text/**".
parameter - the target method parametermessage - the message being processedprotected void validate(Message<?> message, MethodParameter parameter, Object target)
The default implementation checks for @javax.validation.Valid,
Spring's Validated,
and custom annotations whose name starts with "Valid".
message - the currently processed messageparameter - the method parametertarget - the target payload objectMethodArgumentNotValidException - in case of binding errors