spring-framework / org.springframework.messaging.converter / MarshallingMessageConverter

MarshallingMessageConverter

open class MarshallingMessageConverter : 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.

Author
Arjen Poutsma

Since
4.2

Constructors

<init>

MarshallingMessageConverter()

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

MarshallingMessageConverter(vararg supportedMimeTypes: MimeType)

Constructor with a given list of MIME types to support.

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.

Functions

getMarshaller

open fun getMarshaller(): Marshaller

Return the configured Marshaller.

getUnmarshaller

open fun getUnmarshaller(): Unmarshaller

Return the configured unmarshaller.

setMarshaller

open fun setMarshaller(marshaller: Marshaller): Unit

Set the Marshaller to be used by this message converter.

setUnmarshaller

open fun setUnmarshaller(unmarshaller: Unmarshaller): Unit

Set the Unmarshaller to be used by this message converter.

Inherited Functions

fromMessage

fun fromMessage(message: Message<*>, targetClass: Class<*>): Any
fun fromMessage(message: Message<*>, targetClass: Class<*>, conversionHint: Any): Any

getContentTypeResolver

open fun getContentTypeResolver(): ContentTypeResolver

Return the configured ContentTypeResolver.

getSerializedPayloadClass

open fun getSerializedPayloadClass(): Class<*>

Return the configured preferred serialization payload class.

getSupportedMimeTypes

open fun getSupportedMimeTypes(): MutableList<MimeType>

Return the supported MIME types.

isStrictContentTypeMatch

open fun isStrictContentTypeMatch(): Boolean

Whether content type resolution must produce a value that matches one of the supported MIME types.

setContentTypeResolver

open fun setContentTypeResolver(resolver: ContentTypeResolver): Unit

Configure the ContentTypeResolver to use to resolve the content type of an input message.

Note that if no resolver is configured, then strictContentTypeMatch should be left as false (the default) or otherwise this converter will ignore all messages.

By default, a DefaultContentTypeResolver instance is used.

setSerializedPayloadClass

open fun setSerializedPayloadClass(payloadClass: Class<*>): Unit

Configure the preferred serialization class to use (byte[] or String) when converting an Object payload to a Message.

The default value is byte[].

setStrictContentTypeMatch

open fun setStrictContentTypeMatch(strictContentTypeMatch: Boolean): Unit

Whether this converter should convert messages for which no content type could be resolved through the configured org.springframework.messaging.converter.ContentTypeResolver.

A converter can configured to be strict only when a contentTypeResolver is configured and the list of supportedMimeTypes is not be empty.

When this flag is set to true, #supportsMimeType(MessageHeaders) will return false if the contentTypeResolver is not defined or if no content-type header is present.

toMessage

fun toMessage(payload: Any, headers: MessageHeaders): Message<*>
fun toMessage(payload: Any, headers: MessageHeaders, conversionHint: Any): Message<*>