public class Jackson2JsonMessageConverter extends AbstractJsonMessageConverter implements SmartMessageConverter
DEFAULT_CHARSET
Constructor and Description |
---|
Jackson2JsonMessageConverter()
Construct with an internal
ObjectMapper instance
and trusted packed to all (* ). |
Jackson2JsonMessageConverter(com.fasterxml.jackson.databind.ObjectMapper jsonObjectMapper)
Construct with the provided
ObjectMapper instance
and trusted packed to all (* ). |
Jackson2JsonMessageConverter(com.fasterxml.jackson.databind.ObjectMapper jsonObjectMapper,
String... trustedPackages)
Construct with the provided
ObjectMapper instance. |
Jackson2JsonMessageConverter(String... trustedPackages)
Construct with an internal
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.
|
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. |
Jackson2JavaTypeMapper |
getJavaTypeMapper() |
Jackson2JavaTypeMapper.TypePrecedence |
getTypePrecedence()
Return the type precedence.
|
void |
setBeanClassLoader(ClassLoader classLoader) |
void |
setJavaTypeMapper(Jackson2JavaTypeMapper javaTypeMapper) |
void |
setTypePrecedence(Jackson2JavaTypeMapper.TypePrecedence typePrecedence)
Set the precedence for evaluating type information in message properties.
|
getClassLoader, getClassMapper, getDefaultCharset, setClassMapper, setDefaultCharset
isCreateMessageIds, setCreateMessageIds, toMessage
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
toMessage
public Jackson2JsonMessageConverter()
ObjectMapper
instance
and trusted packed to all (*
).public Jackson2JsonMessageConverter(String... trustedPackages)
ObjectMapper
instance.
The DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
is set to false on
the ObjectMapper
.trustedPackages
- the trusted Java packages for deserializationDefaultJackson2JavaTypeMapper.setTrustedPackages(String...)
public Jackson2JsonMessageConverter(com.fasterxml.jackson.databind.ObjectMapper jsonObjectMapper)
ObjectMapper
instance
and trusted packed to all (*
).jsonObjectMapper
- the ObjectMapper
to use.public Jackson2JsonMessageConverter(com.fasterxml.jackson.databind.ObjectMapper jsonObjectMapper, String... trustedPackages)
ObjectMapper
instance.jsonObjectMapper
- the ObjectMapper
to use.trustedPackages
- the trusted Java packages for deserializationDefaultJackson2JavaTypeMapper.setTrustedPackages(String...)
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 void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader
in interface org.springframework.beans.factory.BeanClassLoaderAware
setBeanClassLoader
in class AbstractJsonMessageConverter
public Object fromMessage(Message message) throws MessageConversionException
MessageConverter
fromMessage
in interface MessageConverter
fromMessage
in class AbstractMessageConverter
message
- the message to convertMessageConversionException
- in case of conversion failurepublic Object fromMessage(Message message, 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 payloadmessageProperties
- the message properties (headers)MessageConversionException