Class SerializerMessageConverter
- java.lang.Object
-
- org.springframework.amqp.support.converter.AbstractMessageConverter
-
- org.springframework.amqp.support.converter.AllowedListDeserializingMessageConverter
-
- org.springframework.amqp.support.converter.SerializerMessageConverter
-
- All Implemented Interfaces:
MessageConverter
public class SerializerMessageConverter extends AllowedListDeserializingMessageConverter
Implementation ofMessageConverter
that can work with Strings or native objects of any kind via theSerializer
andDeserializer
abstractions in Spring. TheAbstractMessageConverter.toMessage(Object, MessageProperties)
method simply checks the type of the provided instance while thefromMessage(Message)
method relies upon thecontent-type
of the provided Message.If a
DefaultDeserializer
is configured (default), theallowed patterns
will be applied (if configured); for all other deserializers, the deserializer is responsible for checking classes, if necessary.- Author:
- Dave Syer, Gary Russell
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_CHARSET
-
Constructor Summary
Constructors Constructor Description SerializerMessageConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Message
createMessage(java.lang.Object object, MessageProperties messageProperties)
Creates an AMQP Message from the provided Object.java.lang.Object
fromMessage(Message message)
Converts from a AMQP Message to an Object.void
setDefaultCharset(java.lang.String defaultCharset)
Specify the default charset to use when converting to or from text-based Message body content.void
setDeserializer(Deserializer<java.lang.Object> deserializer)
The deserializer to use for converting from message body to Java object.void
setIgnoreContentType(boolean ignoreContentType)
Flag to signal that the content type should be ignored and the deserializer used irrespective if it is a text message.void
setSerializer(Serializer<java.lang.Object> serializer)
The serializer to use for converting Java objects to message bodies.-
Methods inherited from class org.springframework.amqp.support.converter.AllowedListDeserializingMessageConverter
addAllowedListPatterns, checkAllowedList, setAllowedListPatterns
-
Methods inherited from class org.springframework.amqp.support.converter.AbstractMessageConverter
createMessage, isCreateMessageIds, setCreateMessageIds, toMessage, toMessage
-
-
-
-
Field Detail
-
DEFAULT_CHARSET
public static final java.lang.String DEFAULT_CHARSET
- See Also:
- Constant Field Values
-
-
Method Detail
-
setIgnoreContentType
public void setIgnoreContentType(boolean ignoreContentType)
Flag to signal that the content type should be ignored and the deserializer used irrespective if it is a text message. Defaults to false, in which case the default encoding is used to convert a text message to a String.- Parameters:
ignoreContentType
- the flag value to set
-
setDefaultCharset
public void setDefaultCharset(java.lang.String defaultCharset)
Specify the default charset to use when converting to or from text-based Message body content. If not specified, the charset will be "UTF-8".- Parameters:
defaultCharset
- The default charset.
-
setSerializer
public void setSerializer(Serializer<java.lang.Object> serializer)
The serializer to use for converting Java objects to message bodies.- Parameters:
serializer
- the serializer to set
-
setDeserializer
public void setDeserializer(Deserializer<java.lang.Object> deserializer)
The deserializer to use for converting from message body to Java object.- Parameters:
deserializer
- the deserializer to set
-
fromMessage
public java.lang.Object fromMessage(Message message) throws MessageConversionException
Converts from a AMQP Message to an Object.- Parameters:
message
- the message to convert- Returns:
- the converted Java object
- Throws:
MessageConversionException
- in case of conversion failure
-
createMessage
protected Message createMessage(java.lang.Object object, MessageProperties messageProperties) throws MessageConversionException
Creates an AMQP Message from the provided Object.- Specified by:
createMessage
in classAbstractMessageConverter
- Parameters:
object
- the payload.messageProperties
- the message properties (headers).- Returns:
- a message.
- Throws:
MessageConversionException
-
-