public abstract class AbstractJackson2MessageConverter extends AbstractMessageConverter implements BeanClassLoaderAware, SmartMessageConverter
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CHARSET |
protected Log |
log |
protected com.fasterxml.jackson.databind.ObjectMapper |
objectMapper |
protected boolean |
typeMapperSet |
Modifier | Constructor and Description |
---|---|
protected |
AbstractJackson2MessageConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
MimeType contentType,
String... trustedPackages)
Construct with the provided
ObjectMapper instance. |
Modifier and Type | Method and Description |
---|---|
protected Message |
createMessage(Object objectToConvert,
MessageProperties messageProperties)
Crate a message from the payload object and message properties provided.
|
protected Message |
createMessage(Object objectToConvert,
MessageProperties messageProperties,
Type genericType)
Crate a message from the payload object and message properties provided.
|
Object |
fromMessage(Message message)
Convert from a Message to a Java object.
|
Object |
fromMessage(Message message,
Object conversionHint)
A variant of
MessageConverter.fromMessage(Message) which takes an extra
conversion context as an argument. |
protected ClassLoader |
getClassLoader() |
ClassMapper |
getClassMapper() |
String |
getDefaultCharset() |
Jackson2JavaTypeMapper |
getJavaTypeMapper() |
Jackson2JavaTypeMapper.TypePrecedence |
getTypePrecedence()
Return the type precedence.
|
void |
setBeanClassLoader(ClassLoader classLoader) |
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 |
setJavaTypeMapper(Jackson2JavaTypeMapper javaTypeMapper) |
void |
setTypePrecedence(Jackson2JavaTypeMapper.TypePrecedence typePrecedence)
Set the precedence for evaluating type information in message properties.
|
isCreateMessageIds, setCreateMessageIds, toMessage, toMessage
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
toMessage, toMessage
protected final Log log
public static final String DEFAULT_CHARSET
protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper
protected boolean typeMapperSet
protected AbstractJackson2MessageConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper, MimeType contentType, String... trustedPackages)
ObjectMapper
instance.objectMapper
- the ObjectMapper
to use.contentType
- supported content type when decoding messages, only the subtype
is checked, e.g. */json, */xml.trustedPackages
- the trusted Java packages for deserializationDefaultJackson2JavaTypeMapper.setTrustedPackages(String...)
@Nullable public ClassMapper getClassMapper()
public void setClassMapper(ClassMapper classMapper)
public void setDefaultCharset(@Nullable String defaultCharset)
defaultCharset
- The default charset.public String getDefaultCharset()
public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader
in interface BeanClassLoaderAware
protected ClassLoader getClassLoader()
public Jackson2JavaTypeMapper getJavaTypeMapper()
public void setJavaTypeMapper(Jackson2JavaTypeMapper javaTypeMapper)
public Jackson2JavaTypeMapper.TypePrecedence getTypePrecedence()
setTypePrecedence(Jackson2JavaTypeMapper.TypePrecedence)
public void setTypePrecedence(Jackson2JavaTypeMapper.TypePrecedence typePrecedence)
@RabbitListener
at the method level, the framework attempts
to determine the target type for payload conversion from the method signature.
If so, this type is provided in the
inferredArgumentType
message property.
By default, if the type is concrete (not abstract, not an interface), this will
be used ahead of type information provided in the __TypeId__
and
associated headers provided by the sender.
If you wish to force the use of the __TypeId__
and associated headers
(such as when the actual type is a subclass of the method argument type),
set the precedence to Jackson2JavaTypeMapper.TypePrecedence.TYPE_ID
.
typePrecedence
- the precedence.DefaultJackson2JavaTypeMapper.setTypePrecedence(Jackson2JavaTypeMapper.TypePrecedence)
public Object fromMessage(Message message) throws MessageConversionException
MessageConverter
fromMessage
in interface MessageConverter
message
- the message to convertMessageConversionException
- in case of conversion failurepublic Object fromMessage(Message message, @Nullable Object conversionHint) throws MessageConversionException
MessageConverter.fromMessage(Message)
which takes an extra
conversion context as an argument.fromMessage
in interface SmartMessageConverter
conversionHint
- The conversionHint must be a ParameterizedTypeReference
.message
- the input message.null
if the converter cannot
perform the conversion.MessageConversionException
- if the conversion fails.MessageConverter.fromMessage(Message)
protected Message createMessage(Object objectToConvert, MessageProperties messageProperties) throws MessageConversionException
AbstractMessageConverter
createMessage
in class AbstractMessageConverter
objectToConvert
- the payload.messageProperties
- the message properties (headers).MessageConversionException
protected Message createMessage(Object objectToConvert, MessageProperties messageProperties, @Nullable Type genericType) throws MessageConversionException
AbstractMessageConverter
createMessage
in class AbstractMessageConverter
objectToConvert
- the payloadmessageProperties
- the message properties (headers)genericType
- the type to convert from - used to populate type headers.MessageConversionException