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

AbstractMessageConverter

abstract class AbstractMessageConverter : SmartMessageConverter

Abstract base class for SmartMessageConverter implementations including support for common properties and a partial implementation of the conversion methods, mainly to check if the converter supports the conversion based on the payload class and MIME type.

Author
Rossen Stoyanchev

Author
Sebastien Deleuze

Author
Juergen Hoeller

Since
4.0

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<*>

Inheritors

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.