public class MarshallingMessageConverter extends AbstractMessageConverter implements 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()
|
MarshallingMessageConverter(Marshaller marshaller)
Construct a new
MarshallingMessageConverter with the given Marshaller set. |
MarshallingMessageConverter(Marshaller marshaller,
Unmarshaller unmarshaller)
Construct a new
MarshallingMessageConverter with the
given Marshaller and Unmarshaller. |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected Message |
createMessage(Object object,
MessageProperties messageProperties)
Marshals the given object to a
Message . |
Object |
fromMessage(Message message)
Unmarshals the given
Message into an object. |
void |
setContentType(String contentType)
Set the contentType to be used by this message converter.
|
void |
setMarshaller(Marshaller marshaller)
Set the
Marshaller to be used by this message converter. |
void |
setUnmarshaller(Unmarshaller unmarshaller)
Set the
Unmarshaller to be used by this message converter. |
createMessage, isCreateMessageIds, setCreateMessageIds, toMessage, 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(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 unmarshallerIllegalArgumentException
- when marshaller
does not implement the
Unmarshaller
interface as wellpublic MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)
MarshallingMessageConverter
with the
given Marshaller and Unmarshaller.marshaller
- the Marshaller to useunmarshaller
- the Unmarshaller to usepublic void setContentType(@Nullable String contentType)
contentType
- The content type.public void setMarshaller(Marshaller marshaller)
Marshaller
to be used by this message converter.marshaller
- The marshaller.public void setUnmarshaller(Unmarshaller unmarshaller)
Unmarshaller
to be used by this message converter.unmarshaller
- The unmarshaller.public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
protected Message createMessage(Object object, MessageProperties messageProperties) throws MessageConversionException
Message
.createMessage
in class AbstractMessageConverter
object
- the payload.messageProperties
- the message properties (headers).MessageConversionException
public Object fromMessage(Message message) throws MessageConversionException
Message
into an object.fromMessage
in interface MessageConverter
message
- the message to convertMessageConversionException
- in case of conversion failure