Top Description Fields Constructors Methods
org.springframework.messaging.converter

public Class MarshallingMessageConverter

extends AbstractMessageConverter
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .StringReader, .StringWriter, .Writer, javax.xml.transform.Result, .Source, javax.xml.transform.stream.StreamResult, .StreamSource, org.springframework.beans.TypeMismatchException, org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageHeaders, org.springframework.oxm.Marshaller, .Unmarshaller, org.springframework.util.Assert, .MimeType

Implementation of MessageConverter that can read and write XML using Spring's Marshaller and Unmarshaller abstractions.

This converter requires a Marshaller and Unmarshaller before it can be used. These can be injected by the constructor or bean properties.

Author
Arjen Poutsma
Since
4.2
See Also
Marshaller, Unmarshaller

Field Summary

Modifier and TypeField and Description
private Marshaller
private Unmarshaller
Inherited from org.springframework.messaging.converter.AbstractMessageConverter:
logger

Constructor Summary

AccessConstructor and Description
public
MarshallingMessageConverter()

Default construct allowing for setMarshaller(Marshaller) and/or setUnmarshaller(Unmarshaller) to be invoked separately.

public
MarshallingMessageConverter(MimeType...
the MIME types
supportedMimeTypes
)

Constructor with a given list of MIME types to support.

public
MarshallingMessageConverter(Marshaller
object used as marshaller and unmarshaller
marshaller
)

Constructor with Marshaller.

Method Summary

Modifier and TypeMethod and Description
protected boolean
protected boolean
protected Object
convertFromInternal(Message<?>
the input message
message
,
Class<?>
the target class for the conversion
targetClass
,
Object
an extra object passed to the MessageConverter, e.g. the associated MethodParameter (may be null}
conversionHint
)

Overrides org.springframework.messaging.converter.AbstractMessageConverter.convertFromInternal.

Convert the message payload from serialized form to an Object.

protected Object
convertToInternal(Object
the Object to convert
payload
,
MessageHeaders
optional headers for the message (may be null)
headers
,
Object
an extra object passed to the MessageConverter, e.g. the associated MethodParameter (may be null}
conversionHint
)

Overrides org.springframework.messaging.converter.AbstractMessageConverter.convertToInternal.

Convert the payload object to serialized form.

public Marshaller
getMarshaller()

Return the configured Marshaller.

private Source
getSource(Object payload)

public Unmarshaller
getUnmarshaller()

Return the configured unmarshaller.

public void
setMarshaller(Marshaller marshaller)

Set the Marshaller to be used by this message converter.

public void
setUnmarshaller(Unmarshaller unmarshaller)

Set the Unmarshaller to be used by this message converter.

protected boolean
supports(Class<?>
the class to test for support
clazz
)

Implements abstract org.springframework.messaging.converter.AbstractMessageConverter.supports.

Whether the given class is supported by this converter.

Inherited from org.springframework.messaging.converter.AbstractMessageConverter:
addSupportedMimeTypesfromMessagefromMessagegetContentTypeResolvergetDefaultContentTypegetMimeTypegetResolvedTypegetSerializedPayloadClassgetSupportedMimeTypesisStrictContentTypeMatchsetContentTypeResolversetSerializedPayloadClasssetStrictContentTypeMatchsupportsMimeTypetoMessagetoMessage

Field Detail

marshallerback to summary
private Marshaller marshaller
Annotations
@Nullable
unmarshallerback to summary
private Unmarshaller unmarshaller
Annotations
@Nullable

Constructor Detail

MarshallingMessageConverterback to summary
public MarshallingMessageConverter()

Default construct allowing for setMarshaller(Marshaller) and/or setUnmarshaller(Unmarshaller) to be invoked separately.

MarshallingMessageConverterback to summary
public MarshallingMessageConverter(MimeType... supportedMimeTypes)

Constructor with a given list of MIME types to support.

Parameters
supportedMimeTypes:MimeType[]

the MIME types

MarshallingMessageConverterback to summary
public MarshallingMessageConverter(Marshaller marshaller)

Constructor with Marshaller. If the given Marshaller also implements Unmarshaller, it is also used for unmarshalling.

Note that all Marshaller implementations in Spring also implement Unmarshaller so that you can safely use this constructor.

Parameters
marshaller:Marshaller

object used as marshaller and unmarshaller

Method Detail

canConvertFromback to summary
protected boolean canConvertFrom(Message<?> message, Class<?> targetClass)

Overrides org.springframework.messaging.converter.AbstractMessageConverter.canConvertFrom.

Annotations
@Override
canConvertToback to summary
protected boolean canConvertTo(Object payload, MessageHeaders headers)

Overrides org.springframework.messaging.converter.AbstractMessageConverter.canConvertTo.

Annotations
@Override
convertFromInternalback to summary
protected Object convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint)

Overrides org.springframework.messaging.converter.AbstractMessageConverter.convertFromInternal.

Doc from org.springframework.messaging.converter.AbstractMessageConverter.convertFromInternal.

Convert the message payload from serialized form to an Object.

Parameters
message:Message<?>

the input message

targetClass:Class<?>

the target class for the conversion

conversionHint:Object

an extra object passed to the MessageConverter, e.g. the associated MethodParameter (may be null}

Returns:Object

the result of the conversion, or null if the converter cannot perform the conversion

Annotations
@Override
@Nullable
convertToInternalback to summary
protected Object convertToInternal(Object payload, MessageHeaders headers, Object conversionHint)

Overrides org.springframework.messaging.converter.AbstractMessageConverter.convertToInternal.

Doc from org.springframework.messaging.converter.AbstractMessageConverter.convertToInternal.

Convert the payload object to serialized form.

Parameters
payload:Object

the Object to convert

headers:MessageHeaders

optional headers for the message (may be null)

conversionHint:Object

an extra object passed to the MessageConverter, e.g. the associated MethodParameter (may be null}

Returns:Object

the resulting payload for the message, or null if the converter cannot perform the conversion

Annotations
@Override
@Nullable
getMarshallerback to summary
public Marshaller getMarshaller()

Return the configured Marshaller.

Annotations
@Nullable
getSourceback to summary
private Source getSource(Object payload)
getUnmarshallerback to summary
public Unmarshaller getUnmarshaller()

Return the configured unmarshaller.

Annotations
@Nullable
setMarshallerback to summary
public void setMarshaller(Marshaller marshaller)

Set the Marshaller to be used by this message converter.

setUnmarshallerback to summary
public void setUnmarshaller(Unmarshaller unmarshaller)

Set the Unmarshaller to be used by this message converter.

supportsback to summary
protected boolean supports(Class<?> clazz)

Implements abstract org.springframework.messaging.converter.AbstractMessageConverter.supports.

Doc from org.springframework.messaging.converter.AbstractMessageConverter.supports.

Whether the given class is supported by this converter.

Parameters
clazz:Class<?>

the class to test for support

Returns:boolean

true if supported; false otherwise

Annotations
@Override