Class MessageMethodArgumentResolver
java.lang.Object
org.springframework.messaging.handler.annotation.support.MessageMethodArgumentResolver
- All Implemented Interfaces:
HandlerMethodArgumentResolver
HandlerMethodArgumentResolver
for Message
method arguments.
Validates that the generic type of the payload matches to the message value
or otherwise applies MessageConverter
to convert to the expected
payload type.- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Stephane Nicoll, Juergen Hoeller
-
Constructor Summary
ConstructorDescriptionCreate a default resolver instance without message conversion.MessageMethodArgumentResolver
(MessageConverter converter) Create a resolver instance with the givenMessageConverter
. -
Method Summary
Modifier and TypeMethodDescriptionprotected Class<?>
getPayloadType
(MethodParameter parameter, Message<?> message) Resolve the target class to convert the payload to.protected boolean
isEmptyPayload
(Object payload) Check if the givenpayload
is empty.resolveArgument
(MethodParameter parameter, Message<?> message) Resolves a method parameter into an argument value from a given message.boolean
supportsParameter
(MethodParameter parameter) Whether the given method parameter is supported by this resolver.
-
Constructor Details
-
MessageMethodArgumentResolver
public MessageMethodArgumentResolver()Create a default resolver instance without message conversion. -
MessageMethodArgumentResolver
Create a resolver instance with the givenMessageConverter
.- Parameters:
converter
- the MessageConverter to use (may benull
)- Since:
- 4.3
-
-
Method Details
-
supportsParameter
Description copied from interface:HandlerMethodArgumentResolver
Whether the given method parameter is supported by this resolver.- Specified by:
supportsParameter
in interfaceHandlerMethodArgumentResolver
- Parameters:
parameter
- the method parameter to check- Returns:
true
if this resolver supports the supplied parameter;false
otherwise
-
resolveArgument
Description copied from interface:HandlerMethodArgumentResolver
Resolves a method parameter into an argument value from a given message.- Specified by:
resolveArgument
in interfaceHandlerMethodArgumentResolver
- Parameters:
parameter
- the method parameter to resolve. This parameter must have previously been passed toHandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)
which must have returnedtrue
.message
- the currently processed message- Returns:
- the resolved argument value, or
null
- Throws:
Exception
- in case of errors with the preparation of argument values
-
getPayloadType
Resolve the target class to convert the payload to.By default this is the generic type declared in the
Message
method parameter but that can be overridden to select a more specific target type after also taking into account the "Content-Type", e.g. returnString
if target type isObject
and"Content-Type:text/**"
.- Parameters:
parameter
- the target method parametermessage
- the message being processed- Returns:
- the target type to use
- Since:
- 5.2
-
isEmptyPayload
Check if the givenpayload
is empty.- Parameters:
payload
- the payload to check (can benull
)
-