org.springframework.messaging.converter

## Class MarshallingMessageConverter

- java.lang.Object
- - org.springframework.messaging.converter.AbstractMessageConverter
  - - org.springframework.messaging.converter.MarshallingMessageConverter

All Implemented Interfaces:
  MessageConverter, SmartMessageConverter

    public class MarshallingMessageConverter
    extends AbstractMessageConverter

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.

Since:
  4.2
Author:
  Arjen Poutsma
See Also:
  `Marshaller`, `Unmarshaller`

### Field Summary

### Fields inherited from class org.springframework.messaging.converter.AbstractMessageConverter

`logger`

### Constructor Summary

Constructors
Constructor and Description
`MarshallingMessageConverter()` Default construct allowing for `setMarshaller(Marshaller)` and/or `setUnmarshaller(Unmarshaller)` to be invoked separately.
`MarshallingMessageConverter(org.springframework.oxm.Marshaller marshaller)` Constructor with `Marshaller`.
`MarshallingMessageConverter(org.springframework.util.MimeType... supportedMimeTypes)` Constructor with a given list of MIME types to support.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected boolean` `canConvertFrom(Message<?> message, Class<?> targetClass)`
`protected boolean` `canConvertTo(Object payload, MessageHeaders headers)`
`protected Object` `convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint)` Convert the message payload from serialized form to an Object.
`protected Object` `convertToInternal(Object payload, MessageHeaders headers, Object conversionHint)` Convert the payload object to serialized form.
`org.springframework.oxm.Marshaller` `getMarshaller()` Return the configured Marshaller.
`org.springframework.oxm.Unmarshaller` `getUnmarshaller()` Return the configured unmarshaller.
`void` `setMarshaller(org.springframework.oxm.Marshaller marshaller)` Set the `Marshaller` to be used by this message converter.
`void` `setUnmarshaller(org.springframework.oxm.Unmarshaller unmarshaller)` Set the `Unmarshaller` to be used by this message converter.
`protected boolean` `supports(Class<?> clazz)` Whether the given class is supported by this converter.

### Methods inherited from class org.springframework.messaging.converter.AbstractMessageConverter

`addSupportedMimeTypes, fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, supportsMimeType, toMessage, toMessage`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### MarshallingMessageConverter

    public MarshallingMessageConverter()

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

#### MarshallingMessageConverter

    public MarshallingMessageConverter(org.springframework.util.MimeType... supportedMimeTypes)

Constructor with a given list of MIME types to support.

Parameters:
  `supportedMimeTypes` - the MIME types

#### MarshallingMessageConverter

    public MarshallingMessageConverter(org.springframework.oxm.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` - object used as marshaller and unmarshaller

### Method Detail

#### setMarshaller

    public void setMarshaller(@Nullable
                              org.springframework.oxm.Marshaller marshaller)

Set the `Marshaller` to be used by this message converter.

#### getMarshaller

    @Nullable
    public org.springframework.oxm.Marshaller getMarshaller()

Return the configured Marshaller.

#### setUnmarshaller

    public void setUnmarshaller(@Nullable
                                org.springframework.oxm.Unmarshaller unmarshaller)

Set the `Unmarshaller` to be used by this message converter.

#### getUnmarshaller

    @Nullable
    public org.springframework.oxm.Unmarshaller getUnmarshaller()

Return the configured unmarshaller.

#### canConvertFrom

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

Overrides:
  `canConvertFrom` in class `AbstractMessageConverter`

#### canConvertTo

    protected boolean canConvertTo(Object payload,
                                   @Nullable
                                   MessageHeaders headers)

Overrides:
  `canConvertTo` in class `AbstractMessageConverter`

#### supports

    protected boolean supports(Class<?> clazz)

Description copied from class: `AbstractMessageConverter`
Whether the given class is supported by this converter.

Specified by:
  `supports` in class `AbstractMessageConverter`
Parameters:
  `clazz` - the class to test for support
Returns:
  `true` if supported; `false` otherwise

#### convertFromInternal

    @Nullable
    protected Object convertFromInternal(Message<?> message,
                                                   Class<?> targetClass,
                                                   @Nullable
                                                   Object conversionHint)

Description copied from class: `AbstractMessageConverter`
Convert the message payload from serialized form to an Object.

Overrides:
  `convertFromInternal` in class `AbstractMessageConverter`
Parameters:
  `message` - the input message
  `targetClass` - the target class for the conversion
  `conversionHint` - an extra object passed to the `MessageConverter`, e.g. the associated `MethodParameter` (may be `null`}
Returns:
  the result of the conversion, or `null` if the converter cannot perform the conversion

#### convertToInternal

    @Nullable
    protected Object convertToInternal(Object payload,
                                                 @Nullable
                                                 MessageHeaders headers,
                                                 @Nullable
                                                 Object conversionHint)

Description copied from class: `AbstractMessageConverter`
Convert the payload object to serialized form.

Overrides:
  `convertToInternal` in class `AbstractMessageConverter`
Parameters:
  `payload` - the Object to convert
  `headers` - optional headers for the message (may be `null`)
  `conversionHint` - an extra object passed to the `MessageConverter`, e.g. the associated `MethodParameter` (may be `null`}
Returns:
  the resulting payload for the message, or `null` if the converter cannot perform the conversion