|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.springframework.jms.support.converter.MappingJacksonMessageConverter
public class MappingJacksonMessageConverter
Message converter that uses the Jackson library 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.
| Field Summary | |
|---|---|
static String |
DEFAULT_ENCODING
The default encoding used for writing to text messages: UTF-8. |
| Constructor Summary | |
|---|---|
MappingJacksonMessageConverter()
|
|
| Method Summary | |
|---|---|
protected Object |
convertFromBytesMessage(BytesMessage message,
org.codehaus.jackson.type.JavaType targetJavaType)
Convert a BytesMessage to a Java Object with the specified type. |
protected Object |
convertFromMessage(Message message,
org.codehaus.jackson.type.JavaType targetJavaType)
Template method that allows for custom message mapping. |
protected Object |
convertFromTextMessage(TextMessage message,
org.codehaus.jackson.type.JavaType targetJavaType)
Convert a TextMessage to a Java Object with the specified type. |
Object |
fromMessage(Message message)
Convert from a JMS Message to a Java object. |
protected org.codehaus.jackson.type.JavaType |
getJavaTypeForMessage(Message message)
Determine a Jackson JavaType for the given JMS Message, typically parsing a type id message property. |
protected BytesMessage |
mapToBytesMessage(Object object,
Session session,
org.codehaus.jackson.map.ObjectMapper objectMapper)
Map the given object to a BytesMessage. |
protected Message |
mapToMessage(Object object,
Session session,
org.codehaus.jackson.map.ObjectMapper objectMapper,
MessageType targetType)
Template method that allows for custom message mapping. |
protected TextMessage |
mapToTextMessage(Object object,
Session session,
org.codehaus.jackson.map.ObjectMapper objectMapper)
Map the given object to a TextMessage. |
void |
setEncoding(String encoding)
Specify the encoding to use when converting to and from text-based message body content. |
void |
setEncodingPropertyName(String encodingPropertyName)
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. |
void |
setObjectMapper(org.codehaus.jackson.map.ObjectMapper objectMapper)
Specify the ObjectMapper to use instead of using the default. |
void |
setTargetType(MessageType targetType)
Specify whether toMessage(Object, Session) should marshal to a
BytesMessage or a TextMessage. |
void |
setTypeIdMappings(Map<String,Class<?>> typeIdMappings)
Specify mappings from type ids to Java classes, if desired. |
protected void |
setTypeIdOnMessage(Object object,
Message message)
Set a type id for the given payload object on the given JMS Message. |
void |
setTypeIdPropertyName(String typeIdPropertyName)
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. |
Message |
toMessage(Object object,
Session session)
Convert a Java object to a JMS Message using the supplied session to create the message object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String DEFAULT_ENCODING
| Constructor Detail |
|---|
public MappingJacksonMessageConverter()
| Method Detail |
|---|
public void setObjectMapper(org.codehaus.jackson.map.ObjectMapper objectMapper)
ObjectMapper to use instead of using the default.
public void setTargetType(MessageType targetType)
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.
MessageType.BYTES,
MessageType.TEXTpublic void setEncoding(String encoding)
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(java.lang.String)public void setEncodingPropertyName(String encodingPropertyName)
Default is none. Setting this property is optional; if not set, UTF-8 will be used for decoding any incoming bytes message.
setEncoding(java.lang.String)public void setTypeIdPropertyName(String typeIdPropertyName)
Default is none. NOTE: This property needs to be set in order to allow for converting from an incoming message to a Java object.
setTypeIdMappings(java.util.Map>) public void setTypeIdMappings(Map<String,Class<?>> typeIdMappings)
Default is no custom mappings, i.e. transferring raw Java class names.
typeIdMappings - a Map with type id values as keys and Java classes as values
public Message toMessage(Object object,
Session session)
throws JMSException,
MessageConversionException
MessageConverter
toMessage in interface MessageConverterobject - the object to convertsession - the Session to use for creating a JMS Message
JMSException - if thrown by JMS API methods
MessageConversionException - in case of conversion failure
public Object fromMessage(Message message)
throws JMSException,
MessageConversionException
MessageConverter
fromMessage in interface MessageConvertermessage - the message to convert
JMSException - if thrown by JMS API methods
MessageConversionException - in case of conversion failure
protected TextMessage mapToTextMessage(Object object,
Session session,
org.codehaus.jackson.map.ObjectMapper objectMapper)
throws JMSException,
IOException
TextMessage.
object - the object to be mappedsession - current JMS sessionobjectMapper - the mapper to use
JMSException - if thrown by JMS methods
IOException - in case of I/O errorsSession.createBytesMessage(),
Marshaller.marshal(Object, Result)
protected BytesMessage mapToBytesMessage(Object object,
Session session,
org.codehaus.jackson.map.ObjectMapper objectMapper)
throws JMSException,
IOException
BytesMessage.
object - the object to be mappedsession - current JMS sessionobjectMapper - the mapper to use
JMSException - if thrown by JMS methods
IOException - in case of I/O errorsSession.createBytesMessage(),
Marshaller.marshal(Object, Result)
protected Message mapToMessage(Object object,
Session session,
org.codehaus.jackson.map.ObjectMapper objectMapper,
MessageType targetType)
throws JMSException,
IOException
setTargetType(org.springframework.jms.support.converter.MessageType) is not MessageType.TEXT or
MessageType.BYTES.
The default implementation throws an IllegalArgumentException.
object - the object to marshalsession - the JMS SessionobjectMapper - the mapper to usetargetType - the target message type (other than TEXT or BYTES)
JMSException - if thrown by JMS methods
IOException - in case of I/O errors
protected void setTypeIdOnMessage(Object object,
Message message)
throws JMSException
The default implementation consults the configured type id mapping and sets the resulting value (either a mapped id or the raw Java class name) into the configured type id message property.
object - the payload object to set a type id formessage - the JMS Message to set the type id on
JMSException - if thrown by JMS methodsgetJavaTypeForMessage(javax.jms.Message),
setTypeIdPropertyName(String),
setTypeIdMappings(java.util.Map)
protected Object convertFromTextMessage(TextMessage message,
org.codehaus.jackson.type.JavaType targetJavaType)
throws JMSException,
IOException
message - the input messagetargetJavaType - the target type
JMSException - if thrown by JMS
IOException - in case of I/O errors
protected Object convertFromBytesMessage(BytesMessage message,
org.codehaus.jackson.type.JavaType targetJavaType)
throws JMSException,
IOException
message - the input messagetargetJavaType - the target type
JMSException - if thrown by JMS
IOException - in case of I/O errors
protected Object convertFromMessage(Message message,
org.codehaus.jackson.type.JavaType targetJavaType)
throws JMSException,
IOException
setTargetType(org.springframework.jms.support.converter.MessageType) is not MessageType.TEXT or
MessageType.BYTES.
The default implementation throws an IllegalArgumentException.
message - the input messagetargetJavaType - the target type
JMSException - if thrown by JMS
IOException - in case of I/O errors
protected org.codehaus.jackson.type.JavaType getJavaTypeForMessage(Message message)
throws JMSException
The default implementation parses the configured type id property name and consults the configured type id mapping. This can be overridden with a different strategy, e.g. doing some heuristics based on message origin.
object - the payload object to set a type id formessage - the JMS Message to set the type id on
JMSException - if thrown by JMS methodssetTypeIdOnMessage(Object, javax.jms.Message),
setTypeIdPropertyName(String),
setTypeIdMappings(java.util.Map)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||