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, Ngoc Nhan
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMarshallingMessageConverter(Marshaller marshaller) Construct a newMarshallingMessageConverterwith the givenMarshallerset.MarshallingMessageConverter(Marshaller marshaller, 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(Marshaller marshaller) Set theMarshallerto be used by this message converter.voidsetUnmarshaller(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
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
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
Set theMarshallerto be used by this message converter.- Parameters:
marshaller- The marshaller.
-
setUnmarshaller
Set theUnmarshallerto be used by this message converter.- Parameters:
unmarshaller- The unmarshaller.
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
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
-