Top Description Fields Constructors Methods
org.springframework.messaging.handler.annotation.support

public Class PayloadMethodArgumentResolver

extends Object
implements HandlerMethodArgumentResolver
Class Inheritance
All Implemented Interfaces
org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver
Imports
java.lang.annotation.Annotation, java.util.Optional, org.springframework.core.MethodParameter, org.springframework.lang.Nullable, org.springframework.messaging.Message, org.springframework.messaging.converter.MessageConversionException, .MessageConverter, .SmartMessageConverter, org.springframework.messaging.handler.annotation.Payload, org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver, org.springframework.messaging.support.MessageBuilder, org.springframework.util.Assert, .ClassUtils, .ObjectUtils, .StringUtils, org.springframework.validation.BeanPropertyBindingResult, .BindingResult, .ObjectError, .SmartValidator, .Validator, org.springframework.validation.annotation.ValidationAnnotationUtils

A resolver to extract and convert the payload of a message using a MessageConverter.

Validation is applied if the method argument is annotated with org.springframework.validation.annotation.Validated or @jakarta.validation.Valid. Validation failure results in an MethodArgumentNotValidException.

This HandlerMethodArgumentResolver should be ordered last as it supports all types and does not require the Payload annotation.

Authors
Rossen Stoyanchev, Juergen Hoeller, Brian Clozel, Stephane Nicoll
Since
5.2

Field Summary

Modifier and TypeField and Description
private final MessageConverter
private final boolean
private final Validator

Constructor Summary

AccessConstructor and Description
public
PayloadMethodArgumentResolver(MessageConverter
the MessageConverter to use (required)
messageConverter
)

Create a new PayloadArgumentResolver with the given MessageConverter.

public
PayloadMethodArgumentResolver(MessageConverter
the MessageConverter to use (required)
messageConverter
,
Validator
the Validator to use (optional)
validator
)

Create a new PayloadArgumentResolver with the given MessageConverter and Validator.

public
PayloadMethodArgumentResolver(MessageConverter
the MessageConverter to use (required)
messageConverter
,
Validator
the Validator to use (optional)
validator
,
boolean
if "true" (the default) this resolver supports all parameters; if "false" then only arguments with the @Payload annotation are supported.
useDefaultResolution
)

Create a new PayloadArgumentResolver with the given MessageConverter and Validator.

Method Summary

Modifier and TypeMethod and Description
private String
protected boolean
isEmptyPayload(Object
the payload to check (can be null)
payload
)

Specify if the given payload is empty.

public Object
resolveArgument(MethodParameter
the method parameter to resolve. This parameter must have previously been passed to supportsParameter(org.springframework.core.MethodParameter) which must have returned true.
parameter
,
Message<?>
the currently processed message
message
)

Implements org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver.resolveArgument.

Resolves a method parameter into an argument value from a given message.
protected Class<?>

Returns:

the target type to use
resolveTargetClass
(MethodParameter
the target method parameter
parameter
,
Message<?>
the message being processed
message
)

Resolve the target class to convert the payload to.

public boolean
supportsParameter(MethodParameter
the method parameter to check
parameter
)

Implements org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver.supportsParameter.

Whether the given method parameter is supported by this resolver.
protected void
validate(Message<?>
the currently processed message
message
,
MethodParameter
the method parameter
parameter
,
Object
the target payload object
target
)

Validate the payload if applicable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

converterback to summary
private final MessageConverter converter
useDefaultResolutionback to summary
private final boolean useDefaultResolution
validatorback to summary
private final Validator validator
Annotations
@Nullable

Constructor Detail

PayloadMethodArgumentResolverback to summary
public PayloadMethodArgumentResolver(MessageConverter messageConverter)

Create a new PayloadArgumentResolver with the given MessageConverter.

Parameters
messageConverter:MessageConverter

the MessageConverter to use (required)

PayloadMethodArgumentResolverback to summary
public PayloadMethodArgumentResolver(MessageConverter messageConverter, Validator validator)

Create a new PayloadArgumentResolver with the given MessageConverter and Validator.

Parameters
messageConverter:MessageConverter

the MessageConverter to use (required)

validator:Validator

the Validator to use (optional)

PayloadMethodArgumentResolverback to summary
public PayloadMethodArgumentResolver(MessageConverter messageConverter, Validator validator, boolean useDefaultResolution)

Create a new PayloadArgumentResolver with the given MessageConverter and Validator.

Parameters
messageConverter:MessageConverter

the MessageConverter to use (required)

validator:Validator

the Validator to use (optional)

useDefaultResolution:boolean

if "true" (the default) this resolver supports all parameters; if "false" then only arguments with the @Payload annotation are supported.

Method Detail

getParameterNameback to summary
private String getParameterName(MethodParameter param)
isEmptyPayloadback to summary
protected boolean isEmptyPayload(Object payload)

Specify if the given payload is empty.

Parameters
payload:Object

the payload to check (can be null)

resolveArgumentback to summary
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception

Implements org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver.resolveArgument.

Doc from org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver.resolveArgument.

Resolves a method parameter into an argument value from a given message.

Parameters
parameter:MethodParameter

the method parameter to resolve. This parameter must have previously been passed to supportsParameter(org.springframework.core.MethodParameter) which must have returned true.

message:Message<?>

the currently processed message

Returns:Object

the resolved argument value, or null

Annotations
@Override
@Nullable
Exceptions
Exception:
in case of errors with the preparation of argument values
resolveTargetClassback to summary
protected Class<?> resolveTargetClass(MethodParameter parameter, Message<?> message)

Resolve the target class to convert the payload to.

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/**".

Parameters
parameter:MethodParameter

the target method parameter

message:Message<?>

the message being processed

Returns:Class<?>

the target type to use

Since
5.2
supportsParameterback to summary
public boolean supportsParameter(MethodParameter parameter)

Implements org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver.supportsParameter.

Doc from org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver.supportsParameter.

Whether the given method parameter is supported by this resolver.

Parameters
parameter:MethodParameter

the method parameter to check

Returns:boolean

true if this resolver supports the supplied parameter; false otherwise

Annotations
@Override
validateback to summary
protected void validate(Message<?> message, MethodParameter parameter, Object target)

Validate the payload if applicable.

Parameters
message:Message<?>

the currently processed message

parameter:MethodParameter

the method parameter

target:Object

the target payload object

Exceptions
MethodArgumentNotValidException:
in case of binding errors