Class AbstractJackson2MessageConverter
java.lang.Object
org.springframework.amqp.support.converter.AbstractMessageConverter
org.springframework.amqp.support.converter.AbstractJackson2MessageConverter
- All Implemented Interfaces:
MessageConverter
,SmartMessageConverter
,Aware
,BeanClassLoaderAware
- Direct Known Subclasses:
Jackson2JsonMessageConverter
,Jackson2XmlMessageConverter
@Deprecated(forRemoval=true,
since="4.0")
public abstract class AbstractJackson2MessageConverter
extends AbstractMessageConverter
implements BeanClassLoaderAware, SmartMessageConverter
Deprecated, for removal: This API element is subject to removal in a future version.
Abstract Jackson2 message converter.
- Since:
- 2.1
- Author:
- Mark Pollack, James Carr, Dave Syer, Sam Nelson, Andreas Asplund, Artem Bilan, Mohammad Hewedy, Gary Russell
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Charset
Deprecated, for removal: This API element is subject to removal in a future version.The charset used when convertingString
to/frombyte[]
.protected final Log
Deprecated, for removal: This API element is subject to removal in a future version.protected final com.fasterxml.jackson.databind.ObjectMapper
Deprecated, for removal: This API element is subject to removal in a future version. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractJackson2MessageConverter
(com.fasterxml.jackson.databind.ObjectMapper objectMapper, MimeType contentType, String... trustedPackages) Deprecated, for removal: This API element is subject to removal in a future version.Construct with the providedObjectMapper
instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected Message
createMessage
(Object objectToConvert, MessageProperties messageProperties) Deprecated, for removal: This API element is subject to removal in a future version.Crate a message from the payload object and message properties provided.protected Message
createMessage
(Object objectToConvert, MessageProperties messageProperties, @Nullable Type genericType) Deprecated, for removal: This API element is subject to removal in a future version.Crate a message from the payload object and message properties provided.fromMessage
(Message message) Deprecated, for removal: This API element is subject to removal in a future version.Convert from a Message to a Java object.fromMessage
(Message message, @Nullable Object conversionHint) Deprecated, for removal: This API element is subject to removal in a future version.A variant ofMessageConverter.fromMessage(Message)
which takes an extra conversion context as an argument.protected @Nullable ClassLoader
Deprecated, for removal: This API element is subject to removal in a future version.@Nullable ClassMapper
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.protected MimeType
Deprecated, for removal: This API element is subject to removal in a future version.Get the supported content type; only the subtype is checked when decoding, e.g.Deprecated, for removal: This API element is subject to removal in a future version.Return the type precedence.boolean
Deprecated, for removal: This API element is subject to removal in a future version.Whether an explicit java type mapper has been provided.protected boolean
Deprecated, for removal: This API element is subject to removal in a future version.void
setAlwaysConvertToInferredType
(boolean alwaysAttemptConversion) Deprecated, for removal: This API element is subject to removal in a future version.When false (default), fall back to type id headers if the type (or contents of a container type) is abstract.void
setAssumeSupportedContentType
(boolean assumeSupportedContentType) Deprecated, for removal: This API element is subject to removal in a future version.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) Deprecated, for removal: This API element is subject to removal in a future version.void
setClassMapper
(ClassMapper classMapper) Deprecated, for removal: This API element is subject to removal in a future version.void
setDefaultCharset
(@Nullable String defaultCharset) Deprecated, for removal: This API element is subject to removal in a future version.Specify the default charset to use when converting to or from text-based Message body content.void
setJavaTypeMapper
(Jackson2JavaTypeMapper javaTypeMapper) Deprecated, for removal: This API element is subject to removal in a future version.void
setNullAsOptionalEmpty
(boolean nullAsOptionalEmpty) Deprecated, for removal: This API element is subject to removal in a future version.When true, if jackson decodes the body asnull
convert toOptional.empty()
instead of returning the original body.void
setSupportedContentType
(MimeType supportedContentType) Deprecated, for removal: This API element is subject to removal in a future version.Set the supported content type; only the subtype is checked when decoding, e.g.void
setTypePrecedence
(Jackson2JavaTypeMapper.TypePrecedence typePrecedence) Deprecated, for removal: This API element is subject to removal in a future version.Set the precedence for evaluating type information in message properties.void
setUseProjectionForInterfaces
(boolean useProjectionForInterfaces) Deprecated, for removal: This API element is subject to removal in a future version.Set to true to use Spring Data projection to create the object if the inferred parameter type is an interface.Methods inherited from class org.springframework.amqp.support.converter.AbstractMessageConverter
isCreateMessageIds, setCreateMessageIds, toMessage, toMessage
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.amqp.support.converter.MessageConverter
toMessage, toMessage
-
Field Details
-
DEFAULT_CHARSET
-
log
Deprecated, for removal: This API element is subject to removal in a future version. -
objectMapper
protected final com.fasterxml.jackson.databind.ObjectMapper objectMapperDeprecated, for removal: This API element is subject to removal in a future version.
-
-
Constructor Details
-
AbstractJackson2MessageConverter
protected AbstractJackson2MessageConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper, MimeType contentType, String... trustedPackages) Deprecated, for removal: This API element is subject to removal in a future version.Construct with the providedObjectMapper
instance.- Parameters:
objectMapper
- theObjectMapper
to use.contentType
- the supported content type; only the subtype is checked when decoding, e.g. */json, */xml. If this contains a charset parameter, when encoding, the contentType header will not be set, when decoding, the raw bytes are passed to Jackson which can dynamically determine the encoding; otherwise the contentEncoding or default charset is used.trustedPackages
- the trusted Java packages for deserialization- See Also:
-
-
Method Details
-
getSupportedContentType
Deprecated, for removal: This API element is subject to removal in a future version.Get the supported content type; only the subtype is checked when decoding, e.g. */json, */xml. If this contains a charset parameter, when encoding, the contentType header will not be set, when decoding, the raw bytes are passed to Jackson which can dynamically determine the encoding; otherwise the contentEncoding or default charset is used.- Returns:
- the supportedContentType
- Since:
- 2.4.3
-
setSupportedContentType
Deprecated, for removal: This API element is subject to removal in a future version.Set the supported content type; only the subtype is checked when decoding, e.g. */json, */xml. If this contains a charset parameter, when encoding, the contentType header will not be set, when decoding, the raw bytes are passed to Jackson which can dynamically determine the encoding; otherwise the contentEncoding or default charset is used.- Parameters:
supportedContentType
- the supportedContentType to set.- Since:
- 2.4.3
-
setNullAsOptionalEmpty
public void setNullAsOptionalEmpty(boolean nullAsOptionalEmpty) Deprecated, for removal: This API element is subject to removal in a future version.When true, if jackson decodes the body asnull
convert toOptional.empty()
instead of returning the original body. Default false.- Parameters:
nullAsOptionalEmpty
- true to return empty.- Since:
- 2.4.7
-
getClassMapper
Deprecated, for removal: This API element is subject to removal in a future version. -
setClassMapper
Deprecated, for removal: This API element is subject to removal in a future version. -
setDefaultCharset
Deprecated, for removal: This API element is subject to removal in a future version.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".- Parameters:
defaultCharset
- The default charset.
-
getDefaultCharset
Deprecated, for removal: This API element is subject to removal in a future version. -
setBeanClassLoader
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
setBeanClassLoader
in interfaceBeanClassLoaderAware
-
getClassLoader
Deprecated, for removal: This API element is subject to removal in a future version. -
getJavaTypeMapper
Deprecated, for removal: This API element is subject to removal in a future version. -
isTypeMapperSet
public boolean isTypeMapperSet()Deprecated, for removal: This API element is subject to removal in a future version.Whether an explicit java type mapper has been provided.- Returns:
- false if the default type mapper is being used.
- Since:
- 2.2
- See Also:
-
setJavaTypeMapper
Deprecated, for removal: This API element is subject to removal in a future version. -
getTypePrecedence
Deprecated, for removal: This API element is subject to removal in a future version.Return the type precedence.- Returns:
- the precedence.
- See Also:
-
setTypePrecedence
Deprecated, for removal: This API element is subject to removal in a future version.Set the precedence for evaluating type information in message properties. When using@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 theinferredArgumentType
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 toJackson2JavaTypeMapper.TypePrecedence.TYPE_ID
.- Parameters:
typePrecedence
- the precedence.- See Also:
-
setAlwaysConvertToInferredType
public void setAlwaysConvertToInferredType(boolean alwaysAttemptConversion) Deprecated, for removal: This API element is subject to removal in a future version.When false (default), fall back to type id headers if the type (or contents of a container type) is abstract. Set to true if conversion should always be attempted - perhaps because a custom deserializer has been configured on theObjectMapper
. If the attempt fails, fall back to headers.- Parameters:
alwaysAttemptConversion
- true to attempt.- Since:
- 2.2.8
-
isUseProjectionForInterfaces
protected boolean isUseProjectionForInterfaces()Deprecated, for removal: This API element is subject to removal in a future version. -
setUseProjectionForInterfaces
public void setUseProjectionForInterfaces(boolean useProjectionForInterfaces) Deprecated, for removal: This API element is subject to removal in a future version.Set to true to use Spring Data projection to create the object if the inferred parameter type is an interface.- Parameters:
useProjectionForInterfaces
- true to use projection.- Since:
- 2.2
-
setAssumeSupportedContentType
public void setAssumeSupportedContentType(boolean assumeSupportedContentType) Deprecated, for removal: This API element is subject to removal in a future version.By default, the supported content type is assumed when there is no contentType property, or it is set to the default ('application/octet-stream'). Set to 'false' to revert to the previous behavior of returning an unconverted 'byte[]' when this condition exists.- Parameters:
assumeSupportedContentType
- set false to not assume the content type is supported.- Since:
- 2.2
-
fromMessage
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:MessageConverter
Convert from a Message to a Java object.- Specified by:
fromMessage
in interfaceMessageConverter
- Parameters:
message
- the message to convert- Returns:
- the converted Java object
- Throws:
MessageConversionException
- in case of conversion failure
-
fromMessage
public Object fromMessage(Message message, @Nullable Object conversionHint) throws MessageConversionException Deprecated, for removal: This API element is subject to removal in a future version.A variant ofMessageConverter.fromMessage(Message)
which takes an extra conversion context as an argument.- Specified by:
fromMessage
in interfaceSmartMessageConverter
- Parameters:
message
- the input message.conversionHint
- The conversionHint must be aParameterizedTypeReference
.- Returns:
- the result of the conversion, or
null
if the converter cannot perform the conversion. - Throws:
MessageConversionException
- if the conversion fails.- See Also:
-
createMessage
protected Message createMessage(Object objectToConvert, MessageProperties messageProperties) throws MessageConversionException Deprecated, for removal: This API element is subject to removal in a future version.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 classAbstractMessageConverter
- Parameters:
objectToConvert
- the payload.messageProperties
- the message properties (headers).- Returns:
- a message.
- Throws:
MessageConversionException
-
createMessage
protected Message createMessage(Object objectToConvert, MessageProperties messageProperties, @Nullable Type genericType) throws MessageConversionException Deprecated, for removal: This API element is subject to removal in a future version.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.- Overrides:
createMessage
in classAbstractMessageConverter
- Parameters:
objectToConvert
- the payloadmessageProperties
- the message properties (headers)genericType
- the type to convert from - used to populate type headers.- Returns:
- a message
- Throws:
MessageConversionException
-
AbstractJacksonMessageConverter
for Jackson 3.