public class CompositeMessageConverter extends Object implements MessageConverter
MessageConverter
that delegates to a list of other converters to invoke until
one of them returns a non-null value.Constructor and Description |
---|
CompositeMessageConverter(Collection<MessageConverter> converters)
Create a new instance with the given
MessageConverter s in turn configuring
each with a DefaultContentTypeResolver . |
CompositeMessageConverter(Collection<MessageConverter> converters,
ContentTypeResolver resolver)
Create an instance with the given
MessageConverter s and configure all with
the given ContentTypeResolver . |
Modifier and Type | Method and Description |
---|---|
Object |
fromMessage(Message<?> message,
Class<?> targetClass)
Convert the payload of a
Message from serialized form to a typed Object of
the specified target class. |
ContentTypeResolver |
getContentTypeResolver() |
Collection<MessageConverter> |
getConverters() |
void |
setContentTypeResolver(ContentTypeResolver resolver) |
Message<?> |
toMessage(Object payload,
MessageHeaders headers)
Create a
Message whose payload is the result of converting the given
payload Object to serialized form. |
public CompositeMessageConverter(Collection<MessageConverter> converters)
MessageConverter
s in turn configuring
each with a DefaultContentTypeResolver
.public CompositeMessageConverter(Collection<MessageConverter> converters, ContentTypeResolver resolver)
MessageConverter
s and configure all with
the given ContentTypeResolver
.public void setContentTypeResolver(ContentTypeResolver resolver)
public ContentTypeResolver getContentTypeResolver()
public Collection<MessageConverter> getConverters()
public Object fromMessage(Message<?> message, Class<?> targetClass)
MessageConverter
Message
from 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 conversionpublic Message<?> toMessage(Object payload, 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