public abstract class AbstractJackson2MessageConverter extends AbstractMessageConverter implements BeanClassLoaderAware, SmartMessageConverter
Modifier and Type | Field and Description |
---|---|
static Charset |
DEFAULT_CHARSET
The charset used when converting
String to/from byte[] . |
protected Log |
log |
protected com.fasterxml.jackson.databind.ObjectMapper |
objectMapper |
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.
|
boolean |
isTypeMapperSet()
Whether or not an explicit java type mapper has been provided.
|
protected boolean |
isUseProjectionForInterfaces() |
void |
setAlwaysConvertToInferredType(boolean alwaysAttemptConversion)
When false (default), fall back to type id headers if the type (or contents of a container
type) is abstract.
|
void |
setAssumeSupportedContentType(boolean assumeSupportedContentType)
By default the supported content type is assumed when there is no contentType
property or it is set to the default ('application/octet-stream').
|
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.
|
void |
setUseProjectionForInterfaces(boolean useProjectionForInterfaces)
Set to true to use Spring Data projection to create the object if the inferred
parameter type is an interface.
|
isCreateMessageIds, setCreateMessageIds, toMessage, toMessage
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
toMessage, toMessage
protected final Log log
public static final Charset DEFAULT_CHARSET
String
to/from byte[]
.protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper
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 boolean isTypeMapperSet()
setJavaTypeMapper(Jackson2JavaTypeMapper)
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 setAlwaysConvertToInferredType(boolean alwaysAttemptConversion)
ObjectMapper
. If the attempt fails,
fall back to headers.alwaysAttemptConversion
- true to attempt.protected boolean isUseProjectionForInterfaces()
public void setUseProjectionForInterfaces(boolean useProjectionForInterfaces)
useProjectionForInterfaces
- true to use projection.public void setAssumeSupportedContentType(boolean assumeSupportedContentType)
assumeSupportedContentType
- set false to not assume the content type is
supported.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