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
ConstructorsConstructorDescriptionConstructs an instance using a defaultSimpleMessageConverter.ContentTypeDelegatingMessageConverter(MessageConverter defaultConverter) Constructs an instance using a the supplied default converter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDelegate(String contentType, MessageConverter messageConverter) Add a delegate converter for the content type.fromMessage(Message message) Convert from a Message to a Java object.protected MessageConvertergetConverterForContentType(String contentType) removeDelegate(String contentType) Remove the delegate for the content type.voidsetDelegates(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, waitMethods 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- theMessageConverterfor the content type.- Since:
- 1.6
-
removeDelegate
Remove the delegate for the content type.- Parameters:
contentType- the content type key to removeMessageConverterfrom delegates.- Returns:
- the remove
MessageConverter.
-
fromMessage
Description copied from interface:MessageConverterConvert from a Message to a Java object.- Specified by:
fromMessagein interfaceMessageConverter- Parameters:
message- the message to convert- Returns:
- the converted Java object
- Throws:
MessageConversionException- in case of conversion failure
-
toMessage
Description copied from interface:MessageConverterConvert a Java object to a Message.- Specified by:
toMessagein interfaceMessageConverter- Parameters:
object- the object to convertmessageProperties- The message properties.- Returns:
- the Message
-
getConverterForContentType
-