public class MarshallingMessageConverter extends AbstractMessageConverter implements org.springframework.beans.factory.InitializingBean
MessageConverter
that uses a Marshaller
and Unmarshaller
.
Marshals an object to a Message
and unmarshals a Message
to an object.AmqpTemplate.convertAndSend(Object)
,
AmqpTemplate.receiveAndConvert()
Constructor and Description |
---|
MarshallingMessageConverter()
Construct a new
MarshallingMessageConverter with no Marshaller or Unmarshaller set. |
MarshallingMessageConverter(org.springframework.oxm.Marshaller marshaller)
Construct a new
MarshallingMessageConverter with the given Marshaller set. |
MarshallingMessageConverter(org.springframework.oxm.Marshaller marshaller,
org.springframework.oxm.Unmarshaller unmarshaller)
Construct a new
MarshallingMessageConverter with the
given Marshaller and Unmarshaller. |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected Message |
createMessage(java.lang.Object object,
MessageProperties messageProperties)
Marshals the given object to a
Message . |
java.lang.Object |
fromMessage(Message message)
Unmarshals the given
Message into an object. |
void |
setContentType(java.lang.String contentType)
Set the contentType to be used by this message converter.
|
void |
setMarshaller(org.springframework.oxm.Marshaller marshaller)
Set the
Marshaller to be used by this message converter. |
void |
setUnmarshaller(org.springframework.oxm.Unmarshaller unmarshaller)
Set the
Unmarshaller to be used by this message converter. |
isCreateMessageIds, setCreateMessageIds, toMessage
public MarshallingMessageConverter()
MarshallingMessageConverter
with no Marshaller
or Unmarshaller
set.
The marshaller must be set after construction by invoking setMarshaller(Marshaller)
and
setUnmarshaller(Unmarshaller)
.public MarshallingMessageConverter(org.springframework.oxm.Marshaller marshaller)
MarshallingMessageConverter
with the given Marshaller
set.
If the given Marshaller
also implements the Unmarshaller
interface,
it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.
Note that all Marshaller
implementations in Spring also implement the
Unmarshaller
interface, so that you can safely use this constructor.
marshaller
- object used as marshaller and unmarshallerjava.lang.IllegalArgumentException
- when marshaller
does not implement the
Unmarshaller
interface as wellpublic MarshallingMessageConverter(org.springframework.oxm.Marshaller marshaller, org.springframework.oxm.Unmarshaller unmarshaller)
MarshallingMessageConverter
with the
given Marshaller and Unmarshaller.marshaller
- the Marshaller to useunmarshaller
- the Unmarshaller to usepublic void setContentType(java.lang.String contentType)
contentType
- The content type.public void setMarshaller(org.springframework.oxm.Marshaller marshaller)
Marshaller
to be used by this message converter.marshaller
- The marshaller.public void setUnmarshaller(org.springframework.oxm.Unmarshaller unmarshaller)
Unmarshaller
to be used by this message converter.unmarshaller
- The unmarshaller.public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
protected Message createMessage(java.lang.Object object, MessageProperties messageProperties) throws MessageConversionException
Message
.createMessage
in class AbstractMessageConverter
object
- the payloadmessageProperties
- the message properties (headers)MessageConversionException
public java.lang.Object fromMessage(Message message) throws MessageConversionException
Message
into an object.fromMessage
in interface MessageConverter
fromMessage
in class AbstractMessageConverter
message
- the message to convertMessageConversionException
- in case of conversion failure