Interface MessageConverter
- All Known Subinterfaces:
SmartMessageConverter
- All Known Implementing Classes:
AbstractJsonMessageConverter,AbstractMessageConverter,ByteArrayMessageConverter,CompositeMessageConverter,GenericMessageConverter,GsonMessageConverter,JsonbMessageConverter,KotlinSerializationJsonMessageConverter,MappingJackson2MessageConverter,MarshallingMessageConverter,ProtobufJsonFormatMessageConverter,ProtobufMessageConverter,SimpleMessageConverter,StringMessageConverter
public interface MessageConverter
A converter to turn the payload of a
Message from serialized form to a typed
Object and vice versa. The MessageHeaders.CONTENT_TYPE message header may be
used to specify the media type of the message content.- Since:
- 4.0
- Author:
- Mark Fisher, Rossen Stoyanchev
-
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, MessageHeaders headers) Create aMessagewhose payload is the result of converting the given payload Object to serialized form.
-
Method Details
-
fromMessage
Convert 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.- 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
Create 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.- 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
-