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 Rabbit
MessageConverter
that uses a Marshaller
and Unmarshaller
.
Marshals an object to a Message
and unmarshals a Message
to an object.- Author:
- Mark Fisher, Arjen Poutsma, Juergen Hoeller, James Carr
- See Also:
-
Constructor Summary
ConstructorDescriptionMarshallingMessageConverter
(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
Modifier and TypeMethodDescriptionvoid
protected Message
createMessage
(Object object, MessageProperties messageProperties) Marshals the given object to aMessage
.fromMessage
(Message message) Unmarshals the givenMessage
into an object.void
setContentType
(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 Details
-
MarshallingMessageConverter
public MarshallingMessageConverter()Construct a newMarshallingMessageConverter
with noMarshaller
orUnmarshaller
set. The marshaller must be set after construction by invokingsetMarshaller(Marshaller)
andsetUnmarshaller(Unmarshaller)
. -
MarshallingMessageConverter
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:
IllegalArgumentException
- whenmarshaller
does not implement theUnmarshaller
interface as well
-
MarshallingMessageConverter
Construct a newMarshallingMessageConverter
with the given Marshaller and Unmarshaller.- Parameters:
marshaller
- the Marshaller to useunmarshaller
- the Unmarshaller to use
-
-
Method Details
-
setContentType
Set the contentType to be used by this message converter.- Parameters:
contentType
- The content type.
-
setMarshaller
Set theMarshaller
to be used by this message converter.- Parameters:
marshaller
- The marshaller.
-
setUnmarshaller
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(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
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
-