Class ContentTypeDelegatingMessageConverter
java.lang.Object
org.springframework.amqp.support.converter.ContentTypeDelegatingMessageConverter
- All Implemented Interfaces:
MessageConverter
A composite
MessageConverter
that delegates to an actual MessageConverter
based on the contentType header. Supports a default converter when no content type matches.
Note: the MessageProperties
requires a content type header to select a converter
when used for outbound conversion, but the converter will (generally) override it to match
the actual conversion.- Since:
- 1.4.2
- Author:
- Eric Rizzo, Gary Russell, Artem Bilan
-
Constructor Summary
ConstructorDescriptionConstructs an instance using a defaultSimpleMessageConverter
.ContentTypeDelegatingMessageConverter
(MessageConverter defaultConverter) Constructs an instance using a the supplied default converter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDelegate
(String contentType, MessageConverter messageConverter) Add a delegate converter for the content type.fromMessage
(Message message) Convert from a Message to a Java object.protected MessageConverter
getConverterForContentType
(String contentType) removeDelegate
(String contentType) Remove the delegate for the content type.void
setDelegates
(Map<String, MessageConverter> delegatesByContentType) toMessage
(Object object, MessageProperties messageProperties) Convert a Java object to a Message.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.amqp.support.converter.MessageConverter
toMessage
-
Constructor Details
-
ContentTypeDelegatingMessageConverter
public ContentTypeDelegatingMessageConverter()Constructs an instance using a defaultSimpleMessageConverter
. -
ContentTypeDelegatingMessageConverter
Constructs an instance using a the supplied default converter. May be null meaning a strict content-type match is required.- Parameters:
defaultConverter
- the converter.
-
-
Method Details
-
setDelegates
-
getDelegates
-
addDelegate
Add a delegate converter for the content type.- Parameters:
contentType
- the content type to check.messageConverter
- theMessageConverter
for the content type.- Since:
- 1.6
-
removeDelegate
Remove the delegate for the content type.- Parameters:
contentType
- the content type key to removeMessageConverter
from delegates.- Returns:
- the remove
MessageConverter
.
-
fromMessage
Description copied from interface:MessageConverter
Convert from a Message to a Java object.- Specified by:
fromMessage
in interfaceMessageConverter
- Parameters:
message
- the message to convert- Returns:
- the converted Java object
- Throws:
MessageConversionException
- in case of conversion failure
-
toMessage
Description copied from interface:MessageConverter
Convert a Java object to a Message.- Specified by:
toMessage
in interfaceMessageConverter
- Parameters:
object
- the object to convertmessageProperties
- The message properties.- Returns:
- the Message
-
getConverterForContentType
-