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
ConstructorsConstructorDescriptionCompositeMessageConverter(Collection<MessageConverter> converters) Create an instance with the given converters. -
Method Summary
Modifier and TypeMethodDescriptionfromMessage(Message<?> message, Class<?> targetClass) Convert the payload of aMessagefrom a serialized form to a typed Object of the specified target class.fromMessage(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) A variant ofMessageConverter.fromMessage(Message, Class)which takes an extra conversion context as an argument, allowing to take, for example, annotations on a payload parameter into account.Return the underlying list of delegate converters.toMessage(Object payload, @Nullable MessageHeaders headers) Create aMessagewhose payload is the result of converting the given payload Object to serialized form.A variant ofMessageConverter.toMessage(Object, MessageHeaders)which takes an extra conversion context as an argument, allowing to take, for example, annotations on a return type into account.toString()
-
Constructor Details
-
CompositeMessageConverter
Create an instance with the given converters.
-
-
Method Details
-
fromMessage
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 @Nullable Object fromMessage(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) Description copied from interface:SmartMessageConverterA variant ofMessageConverter.fromMessage(Message, Class)which takes an extra conversion context as an argument, allowing to take, for example, 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, for example, the associatedMethodParameter(may benull)- Returns:
- the result of the conversion, or
nullif the converter cannot perform the conversion - See Also:
-
toMessage
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 @Nullable Message<?> toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) Description copied from interface:SmartMessageConverterA variant ofMessageConverter.toMessage(Object, MessageHeaders)which takes an extra conversion context as an argument, allowing to take, for example, 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, for example, 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:
-
getConverters
Return the underlying list of delegate converters. -
toString
-