org.springframework.messaging.handler.annotation.support

## Class PayloadMethodArgumentResolver

- java.lang.Object
- - org.springframework.messaging.handler.annotation.support.PayloadMethodArgumentResolver

All Implemented Interfaces:
  HandlerMethodArgumentResolver

Direct Known Subclasses:
  PayloadArgumentResolver

    public class PayloadMethodArgumentResolver
    extends Object
    implements HandlerMethodArgumentResolver

A resolver to extract and convert the payload of a message using a `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.

Since:
  5.2
Author:
  Rossen Stoyanchev, Juergen Hoeller, Brian Clozel, Stephane Nicoll

### Constructor Summary

Constructors
Constructor and Description
`PayloadMethodArgumentResolver(MessageConverter messageConverter)` Create a new `PayloadArgumentResolver` with the given `MessageConverter`.
`PayloadMethodArgumentResolver(MessageConverter messageConverter, org.springframework.validation.Validator validator)` Create a new `PayloadArgumentResolver` with the given `MessageConverter` and `Validator`.
`PayloadMethodArgumentResolver(MessageConverter messageConverter, org.springframework.validation.Validator validator, boolean useDefaultResolution)` Create a new `PayloadArgumentResolver` with the given `MessageConverter` and `Validator`.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected boolean` `isEmptyPayload(Object payload)` Specify if the given `payload` is empty.
`Object` `resolveArgument(org.springframework.core.MethodParameter parameter, Message<?> message)` Resolves a method parameter into an argument value from a given message.
`protected Class<?>` `resolveTargetClass(org.springframework.core.MethodParameter parameter, Message<?> message)` Resolve the target class to convert the payload to.
`boolean` `supportsParameter(org.springframework.core.MethodParameter parameter)` Whether the given method parameter is supported by this resolver.
`protected void` `validate(Message<?> message, org.springframework.core.MethodParameter parameter, Object target)` Validate the payload if applicable.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### PayloadMethodArgumentResolver

    public PayloadMethodArgumentResolver(MessageConverter messageConverter)

Create a new `PayloadArgumentResolver` with the given `MessageConverter`.

Parameters:
  `messageConverter` - the MessageConverter to use (required)

#### PayloadMethodArgumentResolver

    public PayloadMethodArgumentResolver(MessageConverter messageConverter,
                                         @Nullable
                                         org.springframework.validation.Validator validator)

Create a new `PayloadArgumentResolver` with the given `MessageConverter` and `Validator`.

Parameters:
  `messageConverter` - the MessageConverter to use (required)
  `validator` - the Validator to use (optional)

#### PayloadMethodArgumentResolver

    public PayloadMethodArgumentResolver(MessageConverter messageConverter,
                                         @Nullable
                                         org.springframework.validation.Validator validator,
                                         boolean useDefaultResolution)

Create a new `PayloadArgumentResolver` with the given `MessageConverter` and `Validator`.

Parameters:
  `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.

### Method Detail

#### supportsParameter

    public boolean supportsParameter(org.springframework.core.MethodParameter parameter)

Description copied from interface: `HandlerMethodArgumentResolver`
Whether the given method parameter is supported by this resolver.

Specified by:
  `supportsParameter` in interface `HandlerMethodArgumentResolver`
Parameters:
  `parameter` - the method parameter to check
Returns:
  `true` if this resolver supports the supplied parameter; `false` otherwise

#### resolveArgument

    @Nullable
    public Object resolveArgument(org.springframework.core.MethodParameter parameter,
                                            Message<?> message)
                                     throws Exception

Description copied from interface: `HandlerMethodArgumentResolver`
Resolves a method parameter into an argument value from a given message.

Specified by:
  `resolveArgument` in interface `HandlerMethodArgumentResolver`
Parameters:
  `parameter` - 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 message
Returns:
  the resolved argument value, or `null`
Throws:
  `Exception` - in case of errors with the preparation of argument values

#### isEmptyPayload

    protected boolean isEmptyPayload(@Nullable
                                     Object payload)

Specify if the given `payload` is empty.

Parameters:
  `payload` - the payload to check (can be `null`)

#### resolveTargetClass

    protected Class<?> resolveTargetClass(org.springframework.core.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` - the target method parameter
  `message` - the message being processed
Returns:
  the target type to use
Since:
  5.2

#### validate

    protected void validate(Message<?> message,
                            org.springframework.core.MethodParameter parameter,
                            Object target)

Validate the payload if applicable.

The default implementation checks for `@javax.validation.Valid`, Spring's `Validated`, and custom annotations whose name starts with "Valid".

Parameters:
  `message` - the currently processed message
  `parameter` - the method parameter
  `target` - the target payload object
Throws:
  `MethodArgumentNotValidException` - in case of binding errors