Top Description Fields Constructors Methods
org.springframework.messaging.converter

public Class CompositeMessageConverter

extends Object
implements SmartMessageConverter
Class Inheritance
All Implemented Interfaces
org.springframework.messaging.converter.SmartMessageConverter, org.springframework.messaging.converter.MessageConverter
Imports
java.util.ArrayList, .Collection, .List, org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageHeaders, org.springframework.util.Assert

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.

Authors
Rossen Stoyanchev, Juergen Hoeller
Since
4.0

Field Summary

Modifier and TypeField and Description
private final List<MessageConverter>

Constructor Summary

AccessConstructor and Description
public
CompositeMessageConverter(Collection<MessageConverter> converters)

Create an instance with the given converters.

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 Object
fromMessage(Message<?>
the input message
message
,
Class<?>
the target class for the conversion
targetClass
,
Object
an extra object passed to the MessageConverter, e.g. the associated MethodParameter (may be null}
conversionHint
)

Implements org.springframework.messaging.converter.SmartMessageConverter.fromMessage.

A variant of fromMessage(Message, Class) which takes an extra conversion context as an argument, allowing to take e.g. annotations on a payload parameter into account.

public List<MessageConverter>
getConverters()

Return the underlying list of delegate converters.

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.

public Message<?>
toMessage(Object
the Object to convert
payload
,
MessageHeaders
optional headers for the message (may be null)
headers
,
Object
an extra object passed to the MessageConverter, e.g. the associated MethodParameter (may be null}
conversionHint
)

Implements org.springframework.messaging.converter.SmartMessageConverter.toMessage.

A variant of toMessage(Object, MessageHeaders) which takes an extra conversion context as an argument, allowing to take e.g. annotations on a return type into account.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

convertersback to summary
private final List<MessageConverter> converters

Constructor Detail

CompositeMessageConverterback to summary
public CompositeMessageConverter(Collection<MessageConverter> converters)

Create an instance with the given converters.

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
fromMessageback to summary
public Object fromMessage(Message<?> message, Class<?> targetClass, Object conversionHint)

Implements org.springframework.messaging.converter.SmartMessageConverter.fromMessage.

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

A variant of fromMessage(Message, Class) which takes an extra conversion context as an argument, allowing to take e.g. annotations on a payload parameter into account.

Parameters
message:Message<?>

the input message

targetClass:Class<?>

the target class for the conversion

conversionHint:Object

an extra object passed to the MessageConverter, e.g. the associated MethodParameter (may be null}

Returns:Object

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

Annotations
@Override
@Nullable
getConvertersback to summary
public List<MessageConverter> getConverters()

Return the underlying list of delegate converters.

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

Implements org.springframework.messaging.converter.SmartMessageConverter.toMessage.

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

A variant of toMessage(Object, MessageHeaders) which takes an extra conversion context as an argument, allowing to take e.g. annotations on a return type into account.

Parameters
payload:Object

the Object to convert

headers:MessageHeaders

optional headers for the message (may be null)

conversionHint:Object

an extra object passed to the MessageConverter, e.g. the associated MethodParameter (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
@Nullable
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override