Class SimpleMessageConverter
java.lang.Object
org.springframework.messaging.converter.SimpleMessageConverter
- All Implemented Interfaces:
MessageConverter
- Direct Known Subclasses:
GenericMessageConverter
A simple converter that simply unwraps the message payload as long as it matches the
expected target class. Or reversely, simply wraps the payload in a message.
Note that this converter ignores any content type information that may be present in message headers and should not be used if payload conversion is actually required.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev
-
Constructor Summary
Constructors -
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.Message<?> toMessage(Object payload, @Nullable MessageHeaders headers) Create aMessagewhose payload is the result of converting the given payload Object to serialized form.
-
Constructor Details
-
SimpleMessageConverter
public SimpleMessageConverter()
-
-
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
-
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
-