public class CompositeMessageConverter extends java.lang.Object implements SmartMessageConverter
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.
Constructor and Description |
---|
CompositeMessageConverter(java.util.Collection<MessageConverter> converters)
Create an instance with the given converters.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
fromMessage(Message<?> message,
java.lang.Class<?> targetClass)
Convert the payload of a
Message from a serialized form to a typed Object
of the specified target class. |
java.lang.Object |
fromMessage(Message<?> message,
java.lang.Class<?> targetClass,
java.lang.Object conversionHint)
A variant of
MessageConverter.fromMessage(Message, Class) which takes an extra
conversion context as an argument, allowing to take e.g. |
java.util.List<MessageConverter> |
getConverters()
Return the underlying list of delegate converters.
|
Message<?> |
toMessage(java.lang.Object payload,
MessageHeaders headers)
Create a
Message whose payload is the result of converting the given
payload Object to serialized form. |
Message<?> |
toMessage(java.lang.Object payload,
MessageHeaders headers,
java.lang.Object conversionHint)
A variant of
MessageConverter.toMessage(Object, MessageHeaders) which takes an extra
conversion context as an argument, allowing to take e.g. |
java.lang.String |
toString() |
public CompositeMessageConverter(java.util.Collection<MessageConverter> converters)
@Nullable public java.lang.Object fromMessage(Message<?> message, java.lang.Class<?> targetClass)
MessageConverter
Message
from a serialized form to a typed Object
of the specified target class. The MessageHeaders.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
.
fromMessage
in interface MessageConverter
message
- the input messagetargetClass
- the target class for the conversionnull
if the converter cannot
perform the conversion@Nullable public java.lang.Object fromMessage(Message<?> message, java.lang.Class<?> targetClass, @Nullable java.lang.Object conversionHint)
SmartMessageConverter
MessageConverter.fromMessage(Message, Class)
which takes an extra
conversion context as an argument, allowing to take e.g. annotations
on a payload parameter into account.fromMessage
in interface SmartMessageConverter
message
- the input messagetargetClass
- the target class for the conversionconversionHint
- an extra object passed to the MessageConverter
,
e.g. the associated MethodParameter
(may be null
}null
if the converter cannot
perform the conversionMessageConverter.fromMessage(Message, Class)
@Nullable public Message<?> toMessage(java.lang.Object payload, @Nullable MessageHeaders headers)
MessageConverter
Message
whose payload is the result of converting the given
payload Object to serialized form. The optional MessageHeaders
parameter
may contain a MessageHeaders.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
.
toMessage
in interface MessageConverter
payload
- the Object to convertheaders
- optional headers for the message (may be null
)null
if the converter does not support the
Object type or the target media type@Nullable public Message<?> toMessage(java.lang.Object payload, @Nullable MessageHeaders headers, @Nullable java.lang.Object conversionHint)
SmartMessageConverter
MessageConverter.toMessage(Object, MessageHeaders)
which takes an extra
conversion context as an argument, allowing to take e.g. annotations
on a return type into account.toMessage
in interface SmartMessageConverter
payload
- the Object to convertheaders
- optional headers for the message (may be null
)conversionHint
- an extra object passed to the MessageConverter
,
e.g. the associated MethodParameter
(may be null
}null
if the converter does not support the
Object type or the target media typeMessageConverter.toMessage(Object, MessageHeaders)
public java.util.List<MessageConverter> getConverters()
public java.lang.String toString()
toString
in class java.lang.Object