Class DefaultJackson2JavaTypeMapper
- java.lang.Object
-
- org.springframework.kafka.support.mapping.AbstractJavaTypeMapper
-
- org.springframework.kafka.support.mapping.DefaultJackson2JavaTypeMapper
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanClassLoaderAware
,ClassMapper
,Jackson2JavaTypeMapper
public class DefaultJackson2JavaTypeMapper extends AbstractJavaTypeMapper implements Jackson2JavaTypeMapper
Jackson 2 type mapper.- Since:
- 2.1
- Author:
- Mark Pollack, Sam Nelson, Andreas Asplund, Artem Bilan, Gary Russell
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.springframework.kafka.support.mapping.Jackson2JavaTypeMapper
Jackson2JavaTypeMapper.TypePrecedence
-
-
Field Summary
-
Fields inherited from class org.springframework.kafka.support.mapping.AbstractJavaTypeMapper
DEFAULT_CLASSID_FIELD_NAME, DEFAULT_CONTENT_CLASSID_FIELD_NAME, DEFAULT_KEY_CLASSID_FIELD_NAME, KEY_DEFAULT_CLASSID_FIELD_NAME, KEY_DEFAULT_CONTENT_CLASSID_FIELD_NAME, KEY_DEFAULT_KEY_CLASSID_FIELD_NAME
-
-
Constructor Summary
Constructors Constructor Description DefaultJackson2JavaTypeMapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTrustedPackages(java.lang.String... packagesToTrust)
Specify a set of packages to trust during deserialization.void
fromClass(java.lang.Class<?> clazz, org.apache.kafka.common.header.Headers headers)
void
fromJavaType(com.fasterxml.jackson.databind.JavaType javaType, org.apache.kafka.common.header.Headers headers)
Jackson2JavaTypeMapper.TypePrecedence
getTypePrecedence()
Return the precedence.void
removeHeaders(org.apache.kafka.common.header.Headers headers)
Remove the type information headers.void
setTypePrecedence(Jackson2JavaTypeMapper.TypePrecedence typePrecedence)
Set the precedence for evaluating type information in message properties.java.lang.Class<?>
toClass(org.apache.kafka.common.header.Headers headers)
com.fasterxml.jackson.databind.JavaType
toJavaType(org.apache.kafka.common.header.Headers headers)
-
Methods inherited from class org.springframework.kafka.support.mapping.AbstractJavaTypeMapper
addHeader, getClassIdFieldName, getClassLoader, getContentClassIdFieldName, getIdClassMapping, getKeyClassIdFieldName, retrieveHeader, retrieveHeaderAsString, setBeanClassLoader, setClassIdFieldName, setContentClassIdFieldName, setIdClassMapping, setKeyClassIdFieldName, setUseForKey
-
-
-
-
Method Detail
-
getTypePrecedence
public Jackson2JavaTypeMapper.TypePrecedence getTypePrecedence()
Return the precedence.- Specified by:
getTypePrecedence
in interfaceJackson2JavaTypeMapper
- Returns:
- the precedence.
- See Also:
setTypePrecedence(Jackson2JavaTypeMapper.TypePrecedence)
-
setTypePrecedence
public void setTypePrecedence(Jackson2JavaTypeMapper.TypePrecedence typePrecedence)
Description copied from interface:Jackson2JavaTypeMapper
Set the precedence for evaluating type information in message properties. When using@KafkaListener
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 by theMessagingMessageListenerAdapter
.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
.- Specified by:
setTypePrecedence
in interfaceJackson2JavaTypeMapper
- Parameters:
typePrecedence
- the precedence.
-
addTrustedPackages
public void addTrustedPackages(java.lang.String... packagesToTrust)
Specify a set of packages to trust during deserialization. The asterisk (*
) means trust all.- Specified by:
addTrustedPackages
in interfaceJackson2JavaTypeMapper
- Parameters:
packagesToTrust
- the trusted Java packages for deserialization
-
toJavaType
public com.fasterxml.jackson.databind.JavaType toJavaType(org.apache.kafka.common.header.Headers headers)
- Specified by:
toJavaType
in interfaceJackson2JavaTypeMapper
-
fromJavaType
public void fromJavaType(com.fasterxml.jackson.databind.JavaType javaType, org.apache.kafka.common.header.Headers headers)
- Specified by:
fromJavaType
in interfaceJackson2JavaTypeMapper
-
fromClass
public void fromClass(java.lang.Class<?> clazz, org.apache.kafka.common.header.Headers headers)
- Specified by:
fromClass
in interfaceClassMapper
-
toClass
public java.lang.Class<?> toClass(org.apache.kafka.common.header.Headers headers)
- Specified by:
toClass
in interfaceClassMapper
-
removeHeaders
public void removeHeaders(org.apache.kafka.common.header.Headers headers)
Description copied from interface:Jackson2JavaTypeMapper
Remove the type information headers.- Specified by:
removeHeaders
in interfaceJackson2JavaTypeMapper
- Parameters:
headers
- the headers.
-
-