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
  • Constructor Details

    • 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 Details

    • 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