Top Description Methods
org.springframework.messaging.converter

public Interface MessageConverter

Known Direct Subinterfaces
org.springframework.messaging.converter.SmartMessageConverter
Known Direct Implementers
org.springframework.messaging.converter.SimpleMessageConverter
Imports
org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageHeaders

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.
Authors
Mark Fisher, Rossen Stoyanchev
Since
4.0

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the result of the conversion, or null if the converter cannot perform the conversion
fromMessage
(Message<?>
the input message
message
,
Class<?>
the target class for the conversion
targetClass
)

Convert the payload of a Message from a serialized form to a typed Object of the specified target class.

public Message<?>

Returns:

the new message, or null if the converter does not support the Object type or the target media type
toMessage
(Object
the Object to convert
payload
,
MessageHeaders
optional headers for the message (may be null)
headers
)

Create a Message whose payload is the result of converting the given payload Object to serialized form.

Method Detail

fromMessageback to summary
public Object fromMessage(Message<?> message, Class<?> targetClass)

Convert the payload of a Message from a 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.

Parameters
message:Message<?>

the input message

targetClass:Class<?>

the target class for the conversion

Returns:Object

the result of the conversion, or null if the converter cannot perform the conversion

Annotations
@Nullable
toMessageback to summary
public Message<?> toMessage(Object payload, MessageHeaders headers)

Create a 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.

Parameters
payload:Object

the Object to convert

headers:MessageHeaders

optional headers for the message (may be null)

Returns:Message<?>

the new message, or null if the converter does not support the Object type or the target media type

Annotations
@Nullable