Top Description Constructors Methods
org.springframework.messaging.converter

public Class SimpleMessageConverter

extends Object
implements MessageConverter
Class Inheritance
All Implemented Interfaces
org.springframework.messaging.converter.MessageConverter
Known Direct Subclasses
org.springframework.messaging.converter.GenericMessageConverter
Imports
org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageHeaders, org.springframework.messaging.support.MessageBuilder, .MessageHeaderAccessor, org.springframework.util.ClassUtils

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.

Author
Rossen Stoyanchev
Since
4.0

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
fromMessage(Message<?>
the input message
message
,
Class<?>
the target class for the conversion
targetClass
)

Implements org.springframework.messaging.converter.MessageConverter.fromMessage.

Convert the payload of a Message from a serialized form to a typed Object of the specified target class.
public Message<?>
toMessage(Object
the Object to convert
payload
,
MessageHeaders
optional headers for the message (may be null)
headers
)

Implements org.springframework.messaging.converter.MessageConverter.toMessage.

Create a Message whose payload is the result of converting the given payload Object to serialized form.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SimpleMessageConverterback to summary
public SimpleMessageConverter()

Method Detail

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

Implements org.springframework.messaging.converter.MessageConverter.fromMessage.

Doc from org.springframework.messaging.converter.MessageConverter.fromMessage.

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
@Override
@Nullable
toMessageback to summary
public Message<?> toMessage(Object payload, MessageHeaders headers)

Implements org.springframework.messaging.converter.MessageConverter.toMessage.

Doc from org.springframework.messaging.converter.MessageConverter.toMessage.

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
@Override