Spring AMQP

org.springframework.amqp.support.converter
Class JsonMessageConverter

java.lang.Object
  extended by org.springframework.amqp.support.converter.AbstractMessageConverter
      extended by org.springframework.amqp.support.converter.JsonMessageConverter
All Implemented Interfaces:
MessageConverter

public class JsonMessageConverter
extends AbstractMessageConverter

JSON converter that uses the Jackson Json library.

Author:
Mark Pollack, James Carr, Dave Syer

Field Summary
static String DEFAULT_CHARSET
           
 
Constructor Summary
JsonMessageConverter()
           
 
Method Summary
protected  Message createMessage(Object objectToConvert, MessageProperties messageProperties)
          Crate a message from the payload object and message properties provided.
 Object fromMessage(Message message)
          Convert from a Message to a Java object.
 ClassMapper getClassMapper()
           
protected  void initializeJsonObjectMapper()
          Subclass and override to customize.
 void setClassMapper(ClassMapper classMapper)
           
 void setDefaultCharset(String defaultCharset)
          Specify the default charset to use when converting to or from text-based Message body content.
 void setJsonObjectMapper(org.codehaus.jackson.map.ObjectMapper jsonObjectMapper)
          The ObjectMapper to use instead of using the default.
 
Methods inherited from class org.springframework.amqp.support.converter.AbstractMessageConverter
isCreateMessageIds, setCreateMessageIds, toMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHARSET

public static final String DEFAULT_CHARSET
See Also:
Constant Field Values
Constructor Detail

JsonMessageConverter

public JsonMessageConverter()
Method Detail

setDefaultCharset

public void setDefaultCharset(String defaultCharset)
Specify the default charset to use when converting to or from text-based Message body content. If not specified, the charset will be "UTF-8".


getClassMapper

public ClassMapper getClassMapper()

setClassMapper

public void setClassMapper(ClassMapper classMapper)

setJsonObjectMapper

public void setJsonObjectMapper(org.codehaus.jackson.map.ObjectMapper jsonObjectMapper)
The ObjectMapper to use instead of using the default. An alternative to injecting a mapper is to extend this class and override initializeJsonObjectMapper().

Parameters:
jsonObjectMapper - the object mapper to set

initializeJsonObjectMapper

protected void initializeJsonObjectMapper()
Subclass and override to customize.


fromMessage

public Object fromMessage(Message message)
                   throws MessageConversionException
Description copied from interface: MessageConverter
Convert from a Message to a Java object.

Specified by:
fromMessage in interface MessageConverter
Specified by:
fromMessage in class AbstractMessageConverter
Parameters:
message - the message to convert
Returns:
the converted Java object
Throws:
MessageConversionException - in case of conversion failure

createMessage

protected Message createMessage(Object objectToConvert,
                                MessageProperties messageProperties)
                         throws MessageConversionException
Description copied from class: AbstractMessageConverter
Crate a message from the payload object and message properties provided. The message id will be added to the properties if necessary later.

Specified by:
createMessage in class AbstractMessageConverter
Parameters:
objectToConvert - the payload
messageProperties - the message properties (headers)
Returns:
a message
Throws:
MessageConversionException

Spring AMQP

Copyright © 2011. All Rights Reserved.