Class CompositeMessageConverter
java.lang.Object
org.springframework.messaging.converter.CompositeMessageConverter
- All Implemented Interfaces:
MessageConverter
,SmartMessageConverter
A
MessageConverter
that delegates to a list of registered converters
to be invoked until one of them returns a non-null result.
As of 4.2.1, this composite converter implements SmartMessageConverter
in order to support the delegation of conversion hints.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller
-
Constructor Summary
ConstructorDescriptionCompositeMessageConverter
(Collection<MessageConverter> converters) Create an instance with the given converters. -
Method Summary
Modifier and TypeMethodDescriptionfromMessage
(Message<?> message, Class<?> targetClass) Convert the payload of aMessage
from a serialized form to a typed Object of the specified target class.fromMessage
(Message<?> message, Class<?> targetClass, Object conversionHint) A variant ofMessageConverter.fromMessage(Message, Class)
which takes an extra conversion context as an argument, allowing to take e.g.Return the underlying list of delegate converters.Message<?>
toMessage
(Object payload, MessageHeaders headers) Create aMessage
whose payload is the result of converting the given payload Object to serialized form.Message<?>
toMessage
(Object payload, MessageHeaders headers, Object conversionHint) A variant ofMessageConverter.toMessage(Object, MessageHeaders)
which takes an extra conversion context as an argument, allowing to take e.g.toString()
-
Constructor Details
-
CompositeMessageConverter
Create an instance with the given converters.
-
-
Method Details
-
fromMessage
Description copied from interface:MessageConverter
Convert the payload of aMessage
from a serialized form to a typed Object of the specified target class. TheMessageHeaders.CONTENT_TYPE
header should indicate the MIME type to convert from.If the converter does not support the specified media type or cannot perform the conversion, it should return
null
.- Specified by:
fromMessage
in interfaceMessageConverter
- Parameters:
message
- the input messagetargetClass
- the target class for the conversion- Returns:
- the result of the conversion, or
null
if the converter cannot perform the conversion
-
fromMessage
@Nullable public Object fromMessage(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) Description copied from interface:SmartMessageConverter
A variant ofMessageConverter.fromMessage(Message, Class)
which takes an extra conversion context as an argument, allowing to take e.g. annotations on a payload parameter into account.- Specified by:
fromMessage
in interfaceSmartMessageConverter
- Parameters:
message
- the input messagetargetClass
- the target class for the conversionconversionHint
- an extra object passed to theMessageConverter
, e.g. the associatedMethodParameter
(may benull
}- Returns:
- the result of the conversion, or
null
if the converter cannot perform the conversion - See Also:
-
toMessage
Description copied from interface:MessageConverter
Create aMessage
whose payload is the result of converting the given payload Object to serialized form. The optionalMessageHeaders
parameter may contain aMessageHeaders.CONTENT_TYPE
header to specify the target media type for the conversion and it may contain additional headers to be added to the message.If the converter does not support the specified media type or cannot perform the conversion, it should return
null
.- Specified by:
toMessage
in interfaceMessageConverter
- Parameters:
payload
- the Object to convertheaders
- optional headers for the message (may benull
)- Returns:
- the new message, or
null
if the converter does not support the Object type or the target media type
-
toMessage
@Nullable public Message<?> toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) Description copied from interface:SmartMessageConverter
A variant ofMessageConverter.toMessage(Object, MessageHeaders)
which takes an extra conversion context as an argument, allowing to take e.g. annotations on a return type into account.- Specified by:
toMessage
in interfaceSmartMessageConverter
- Parameters:
payload
- the Object to convertheaders
- optional headers for the message (may benull
)conversionHint
- an extra object passed to theMessageConverter
, e.g. the associatedMethodParameter
(may benull
}- Returns:
- the new message, or
null
if the converter does not support the Object type or the target media type - See Also:
-
getConverters
Return the underlying list of delegate converters. -
toString
-