Class MarshallingMessageConverter
- java.lang.Object
-
- org.springframework.amqp.support.converter.AbstractMessageConverter
-
- org.springframework.amqp.support.converter.MarshallingMessageConverter
-
- All Implemented Interfaces:
MessageConverter
,InitializingBean
public class MarshallingMessageConverter extends AbstractMessageConverter implements InitializingBean
Spring RabbitMessageConverter
that uses aMarshaller
andUnmarshaller
. Marshals an object to aMessage
and unmarshals aMessage
to an object.- Author:
- Mark Fisher, Arjen Poutsma, Juergen Hoeller, James Carr
- See Also:
AmqpTemplate.convertAndSend(Object)
,AmqpTemplate.receiveAndConvert()
-
-
Constructor Summary
Constructors Constructor Description MarshallingMessageConverter()
MarshallingMessageConverter(Marshaller marshaller)
Construct a newMarshallingMessageConverter
with the givenMarshaller
set.MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)
Construct a newMarshallingMessageConverter
with the given Marshaller and Unmarshaller.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
protected Message
createMessage(java.lang.Object object, MessageProperties messageProperties)
Marshals the given object to aMessage
.java.lang.Object
fromMessage(Message message)
Unmarshals the givenMessage
into an object.void
setContentType(java.lang.String contentType)
Set the contentType to be used by this message converter.void
setMarshaller(Marshaller marshaller)
Set theMarshaller
to be used by this message converter.void
setUnmarshaller(Unmarshaller unmarshaller)
Set theUnmarshaller
to be used by this message converter.-
Methods inherited from class org.springframework.amqp.support.converter.AbstractMessageConverter
createMessage, isCreateMessageIds, setCreateMessageIds, toMessage, toMessage
-
-
-
-
Constructor Detail
-
MarshallingMessageConverter
public MarshallingMessageConverter()
Construct a newMarshallingMessageConverter
with noMarshaller
orUnmarshaller
set. The marshaller must be set after construction by invokingsetMarshaller(Marshaller)
andsetUnmarshaller(Unmarshaller)
.
-
MarshallingMessageConverter
public MarshallingMessageConverter(Marshaller marshaller)
Construct a newMarshallingMessageConverter
with the givenMarshaller
set.If the given
Marshaller
also implements theUnmarshaller
interface, it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.Note that all
Marshaller
implementations in Spring also implement theUnmarshaller
interface, so that you can safely use this constructor.- Parameters:
marshaller
- object used as marshaller and unmarshaller- Throws:
java.lang.IllegalArgumentException
- whenmarshaller
does not implement theUnmarshaller
interface as well
-
MarshallingMessageConverter
public MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)
Construct a newMarshallingMessageConverter
with the given Marshaller and Unmarshaller.- Parameters:
marshaller
- the Marshaller to useunmarshaller
- the Unmarshaller to use
-
-
Method Detail
-
setContentType
public void setContentType(@Nullable java.lang.String contentType)
Set the contentType to be used by this message converter.- Parameters:
contentType
- The content type.
-
setMarshaller
public void setMarshaller(Marshaller marshaller)
Set theMarshaller
to be used by this message converter.- Parameters:
marshaller
- The marshaller.
-
setUnmarshaller
public void setUnmarshaller(Unmarshaller unmarshaller)
Set theUnmarshaller
to be used by this message converter.- Parameters:
unmarshaller
- The unmarshaller.
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
createMessage
protected Message createMessage(java.lang.Object object, MessageProperties messageProperties) throws MessageConversionException
Marshals the given object to aMessage
.- Specified by:
createMessage
in classAbstractMessageConverter
- Parameters:
object
- the payload.messageProperties
- the message properties (headers).- Returns:
- a message.
- Throws:
MessageConversionException
-
fromMessage
public java.lang.Object fromMessage(Message message) throws MessageConversionException
Unmarshals the givenMessage
into 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
-
-