Class SimpleMessageConverter
java.lang.Object
org.springframework.amqp.support.converter.AbstractMessageConverter
org.springframework.amqp.support.converter.AllowedListDeserializingMessageConverter
org.springframework.amqp.support.converter.SimpleMessageConverter
- All Implemented Interfaces:
MessageConverter
,Aware
,BeanClassLoaderAware
public class SimpleMessageConverter
extends AllowedListDeserializingMessageConverter
implements BeanClassLoaderAware
Implementation of
MessageConverter
that can work with Strings, Serializable
instances, or byte arrays. The AbstractMessageConverter.toMessage(Object, MessageProperties)
method
simply checks the type of the provided instance while the fromMessage(Message)
method relies upon the content-type
of the
provided Message.- Author:
- Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Message
createMessage
(Object object, MessageProperties messageProperties) Creates an AMQP Message from the provided Object.protected ObjectInputStream
Create an ObjectInputStream for the given InputStream.fromMessage
(Message message) Converts from a AMQP Message to an Object.void
setBeanClassLoader
(ClassLoader classLoader) void
setDefaultCharset
(String defaultCharset) Specify the default charset to use when converting to or from text-based Message body content.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 Details
-
DEFAULT_CHARSET
- See Also:
-
-
Constructor Details
-
SimpleMessageConverter
public SimpleMessageConverter()
-
-
Method Details
-
setDefaultCharset
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.
-
setBeanClassLoader
- Specified by:
setBeanClassLoader
in interfaceBeanClassLoaderAware
-
fromMessage
Converts from a AMQP Message to an Object.- Specified by:
fromMessage
in interfaceMessageConverter
- Parameters:
message
- the message to convert- Returns:
- the converted Java object
- Throws:
MessageConversionException
- in case of conversion failure
-
createMessage
protected Message createMessage(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
-
createObjectInputStream
Create an ObjectInputStream for the given InputStream. The default implementation creates anConfigurableObjectInputStream
against configuredClassLoader
. The class for object to deserialize is checked againstallowedListPatterns
.- Parameters:
is
- the InputStream to read from- Returns:
- the new ObjectInputStream instance to use
- Throws:
IOException
- if creation of the ObjectInputStream failed
-