Class MarshallingMessageConverter
- java.lang.Object
-
- org.springframework.amqp.support.converter.AbstractMessageConverter
-
- org.springframework.amqp.support.converter.MarshallingMessageConverter
-
- All Implemented Interfaces:
MessageConverter,org.springframework.beans.factory.InitializingBean
public class MarshallingMessageConverter extends AbstractMessageConverter implements org.springframework.beans.factory.InitializingBean
Spring RabbitMessageConverterthat uses aMarshallerandUnmarshaller. Marshals an object to aMessageand unmarshals aMessageto an object.
-
-
Constructor Summary
Constructors Constructor Description MarshallingMessageConverter()Construct a newMarshallingMessageConverterwith noMarshallerorUnmarshallerset.MarshallingMessageConverter(org.springframework.oxm.Marshaller marshaller)Construct a newMarshallingMessageConverterwith the givenMarshallerset.MarshallingMessageConverter(org.springframework.oxm.Marshaller marshaller, org.springframework.oxm.Unmarshaller unmarshaller)Construct a newMarshallingMessageConverterwith the given Marshaller and Unmarshaller.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()protected MessagecreateMessage(java.lang.Object object, MessageProperties messageProperties)Marshals the given object to aMessage.java.lang.ObjectfromMessage(Message message)Unmarshals the givenMessageinto an object.voidsetContentType(java.lang.String contentType)Set the contentType to be used by this message converter.voidsetMarshaller(org.springframework.oxm.Marshaller marshaller)Set theMarshallerto be used by this message converter.voidsetUnmarshaller(org.springframework.oxm.Unmarshaller unmarshaller)Set theUnmarshallerto 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 newMarshallingMessageConverterwith noMarshallerorUnmarshallerset. The marshaller must be set after construction by invokingsetMarshaller(Marshaller)andsetUnmarshaller(Unmarshaller).
-
MarshallingMessageConverter
public MarshallingMessageConverter(org.springframework.oxm.Marshaller marshaller)
Construct a newMarshallingMessageConverterwith the givenMarshallerset.If the given
Marshalleralso implements theUnmarshallerinterface, it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.Note that all
Marshallerimplementations in Spring also implement theUnmarshallerinterface, so that you can safely use this constructor.- Parameters:
marshaller- object used as marshaller and unmarshaller- Throws:
java.lang.IllegalArgumentException- whenmarshallerdoes not implement theUnmarshallerinterface as well
-
MarshallingMessageConverter
public MarshallingMessageConverter(org.springframework.oxm.Marshaller marshaller, org.springframework.oxm.Unmarshaller unmarshaller)Construct a newMarshallingMessageConverterwith 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(org.springframework.oxm.Marshaller marshaller)
Set theMarshallerto be used by this message converter.- Parameters:
marshaller- The marshaller.
-
setUnmarshaller
public void setUnmarshaller(org.springframework.oxm.Unmarshaller unmarshaller)
Set theUnmarshallerto be used by this message converter.- Parameters:
unmarshaller- The unmarshaller.
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
createMessage
protected Message createMessage(java.lang.Object object, MessageProperties messageProperties) throws MessageConversionException
Marshals the given object to aMessage.- Specified by:
createMessagein 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 givenMessageinto an object.- Specified by:
fromMessagein interfaceMessageConverter- Parameters:
message- the message to convert- Returns:
- the converted Java object
- Throws:
MessageConversionException- in case of conversion failure
-
-