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 Rabbit
MessageConverter that uses a Marshaller and Unmarshaller.
Marshals an object to a Message and unmarshals a Message to an object.-
Constructor Summary
ConstructorsConstructorDescriptionConstruct 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
Modifier and TypeMethodDescriptionvoidprotected MessagecreateMessage(Object object, MessageProperties messageProperties) Marshals the given object to aMessage.fromMessage(Message message) Unmarshals the givenMessageinto an object.voidsetContentType(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 Details
-
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:
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 Details
-
setContentType
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(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
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
-