spring-framework / org.springframework.jms.support.converter / MappingJackson2MessageConverter

MappingJackson2MessageConverter

open class MappingJackson2MessageConverter : SmartMessageConverter, BeanClassLoaderAware

Message converter that uses Jackson 2.x to convert messages to and from JSON. Maps an object to a BytesMessage, or to a TextMessage if the targetType is set to MessageType#TEXT. Converts from a TextMessage or BytesMessage to an object.

It customizes Jackson's default properties with the following ones:

Compatible with Jackson 2.6 and higher, as of Spring 4.3.

Author
Mark Pollack

Author
Dave Syer

Author
Juergen Hoeller

Author
Stephane Nicoll

Since
3.1.4

Constructors

<init>

MappingJackson2MessageConverter()

Properties

DEFAULT_ENCODING

static val DEFAULT_ENCODING: String

The default encoding used for writing to text messages: UTF-8.

Functions

fromMessage

open fun fromMessage(message: Message): Any

setBeanClassLoader

open fun setBeanClassLoader(classLoader: ClassLoader): Unit

setEncoding

open fun setEncoding(encoding: String): Unit

Specify the encoding to use when converting to and from text-based message body content. The default encoding will be "UTF-8".

When reading from a a text-based message, an encoding may have been suggested through a special JMS property which will then be preferred over the encoding set on this MessageConverter instance.

setEncodingPropertyName

open fun setEncodingPropertyName(encodingPropertyName: String): Unit

Specify the name of the JMS message property that carries the encoding from bytes to String and back is BytesMessage is used during the conversion process.

Default is none. Setting this property is optional; if not set, UTF-8 will be used for decoding any incoming bytes message.

setObjectMapper

open fun setObjectMapper(objectMapper: ObjectMapper): Unit

Specify the ObjectMapper to use instead of using the default.

setTargetType

open fun setTargetType(targetType: MessageType): Unit

Specify whether #toMessage(Object, Session) should marshal to a BytesMessage or a TextMessage.

The default is MessageType#BYTES, i.e. this converter marshals to a BytesMessage. Note that the default version of this converter supports MessageType#BYTES and MessageType#TEXT only.

setTypeIdMappings

open fun setTypeIdMappings(typeIdMappings: MutableMap<String, Class<*>>): Unit

Specify mappings from type ids to Java classes, if desired. This allows for synthetic ids in the type id message property, instead of transferring Java class names.

Default is no custom mappings, i.e. transferring raw Java class names.

setTypeIdPropertyName

open fun setTypeIdPropertyName(typeIdPropertyName: String): Unit

Specify the name of the JMS message property that carries the type id for the contained object: either a mapped id value or a raw Java class name.

Default is none. NOTE: This property needs to be set in order to allow for converting from an incoming message to a Java object.

toMessage

open fun toMessage(object: Any, session: Session): Message
open fun toMessage(object: Any, session: Session, conversionHint: Any): Messageopen fun toMessage(object: Any, session: Session, jsonView: Class<*>): Message

Convert a Java object to a JMS Message using the specified json view and the supplied session to create the message object.