Class CompositeMessageConverter
- java.lang.Object
- org.springframework.messaging.converter.CompositeMessageConverter
- All Implemented Interfaces:
MessageConverter,SmartMessageConverter
public class CompositeMessageConverter extends Object implements SmartMessageConverter
AMessageConverterthat 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
SmartMessageConverterin order to support the delegation of conversion hints.- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller
Constructor Summary
Constructors Constructor Description CompositeMessageConverter(Collection<MessageConverter> converters)Create an instance with the given converters.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectfromMessage(Message<?> message, Class<?> targetClass)Convert the payload of aMessagefrom a serialized form to a typed Object of the specified target class.ObjectfromMessage(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.List<MessageConverter>getConverters()Return the underlying list of delegate converters.Message<?>toMessage(Object payload, MessageHeaders headers)Create aMessagewhose 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.StringtoString()
Constructor Detail
CompositeMessageConverter
public CompositeMessageConverter(Collection<MessageConverter> converters)
Create an instance with the given converters.
Method Detail
fromMessage
public Object fromMessage(Message<?> message, Class<?> targetClass)
Description copied from interface:MessageConverterConvert the payload of aMessagefrom a serialized form to a typed Object of the specified target class. TheMessageHeaders.CONTENT_TYPEheader 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:
fromMessagein interfaceMessageConverter- Parameters:
message- the input messagetargetClass- the target class for the conversion- Returns:
- the result of the conversion, or
nullif the converter cannot perform the conversion
fromMessage
public Object fromMessage(Message<?> message, Class<?> targetClass, Object conversionHint)
Description copied from interface:SmartMessageConverterA 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:
fromMessagein 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
nullif the converter cannot perform the conversion - See Also:
MessageConverter.fromMessage(Message, Class)
toMessage
public Message<?> toMessage(Object payload, MessageHeaders headers)
Description copied from interface:MessageConverterCreate aMessagewhose payload is the result of converting the given payload Object to serialized form. The optionalMessageHeadersparameter may contain aMessageHeaders.CONTENT_TYPEheader 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:
toMessagein interfaceMessageConverter- Parameters:
payload- the Object to convertheaders- optional headers for the message (may benull)- Returns:
- the new message, or
nullif the converter does not support the Object type or the target media type
toMessage
public Message<?> toMessage(Object payload, MessageHeaders headers, Object conversionHint)
Description copied from interface:SmartMessageConverterA 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:
toMessagein 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
nullif the converter does not support the Object type or the target media type - See Also:
MessageConverter.toMessage(Object, MessageHeaders)
getConverters
public List<MessageConverter> getConverters()
Return the underlying list of delegate converters.