Class JacksonJsonSerde<T>
java.lang.Object
org.springframework.kafka.support.serializer.JacksonJsonSerde<T>
- Type Parameters:
T
- target class for serialization/deserialization
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.apache.kafka.common.serialization.Serde<T>
public class JacksonJsonSerde<T>
extends Object
implements org.apache.kafka.common.serialization.Serde<T>
A
Serde
that provides serialization and
deserialization in JSON format. Based on Jackson 3.
The implementation delegates to underlying JacksonJsonSerializer
and
JacksonJsonDeserializer
implementations.
- Since:
- 4.0
- Author:
- Marius Bogoevici, Elliot Kennedy, Gary Russell, Ivan Ponomarev, Soby Chacko
-
Constructor Summary
ConstructorsConstructorDescriptionJacksonJsonSerde
(@Nullable Class<? super T> targetType) JacksonJsonSerde
(@Nullable Class<? super T> targetType, tools.jackson.databind.json.JsonMapper jsonMapper) JacksonJsonSerde
(JacksonJsonSerializer<T> jsonSerializer, JacksonJsonDeserializer<T> jsonDeserializer) JacksonJsonSerde
(@Nullable tools.jackson.core.type.TypeReference<? super T> targetType) JacksonJsonSerde
(@Nullable tools.jackson.core.type.TypeReference<? super T> targetType, tools.jackson.databind.json.JsonMapper jsonMapper) JacksonJsonSerde
(@Nullable tools.jackson.databind.JavaType targetType) JacksonJsonSerde
(@Nullable tools.jackson.databind.JavaType targetTypeArg, @Nullable tools.jackson.databind.json.JsonMapper jsonMapperArg) JacksonJsonSerde
(tools.jackson.databind.json.JsonMapper jsonMapper) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
<X> JacksonJsonSerde
<X> copyWithType
(Class<? super X> newTargetType) Copies this serde with same configuration, except new target type is used.<X> JacksonJsonSerde
<X> copyWithType
(tools.jackson.core.type.TypeReference<? super X> newTargetType) Copies this serde with same configuration, except new target type reference is used.<X> JacksonJsonSerde
<X> copyWithType
(tools.jackson.databind.JavaType newTargetType) Copies this serde with same configuration, except new target java type is used.Don't remove type information headers after deserialization.forKeys()
Designate this Serde for serializing/deserializing keys (default is values).Ignore type information headers and use the configured target class.Configure the serializer to not add type information.typeMapper
(JacksonJavaTypeMapper mapper) Use the suppliedJacksonJavaTypeMapper
.
-
Constructor Details
-
JacksonJsonSerde
public JacksonJsonSerde() -
JacksonJsonSerde
-
JacksonJsonSerde
-
JacksonJsonSerde
public JacksonJsonSerde(@Nullable tools.jackson.databind.JavaType targetType) -
JacksonJsonSerde
public JacksonJsonSerde(tools.jackson.databind.json.JsonMapper jsonMapper) -
JacksonJsonSerde
public JacksonJsonSerde(@Nullable tools.jackson.core.type.TypeReference<? super T> targetType, tools.jackson.databind.json.JsonMapper jsonMapper) -
JacksonJsonSerde
-
JacksonJsonSerde
public JacksonJsonSerde(@Nullable tools.jackson.databind.JavaType targetTypeArg, @Nullable tools.jackson.databind.json.JsonMapper jsonMapperArg) -
JacksonJsonSerde
public JacksonJsonSerde(JacksonJsonSerializer<T> jsonSerializer, JacksonJsonDeserializer<T> jsonDeserializer)
-
-
Method Details
-
configure
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceorg.apache.kafka.common.serialization.Serde<T>
-
serializer
- Specified by:
serializer
in interfaceorg.apache.kafka.common.serialization.Serde<T>
-
deserializer
- Specified by:
deserializer
in interfaceorg.apache.kafka.common.serialization.Serde<T>
-
copyWithType
Copies this serde with same configuration, except new target type is used.- Type Parameters:
X
- new deserialization result type and serialization source type- Parameters:
newTargetType
- type reference forced for serialization, and used as default for deserialization, not null- Returns:
- new instance of serde with type changes
-
copyWithType
public <X> JacksonJsonSerde<X> copyWithType(tools.jackson.core.type.TypeReference<? super X> newTargetType) Copies this serde with same configuration, except new target type reference is used.- Type Parameters:
X
- new deserialization result type and serialization source type- Parameters:
newTargetType
- type reference forced for serialization, and used as default for deserialization, not null- Returns:
- new instance of serde with type changes
-
copyWithType
Copies this serde with same configuration, except new target java type is used.- Type Parameters:
X
- new deserialization result type and serialization source type- Parameters:
newTargetType
- java type forced for serialization, and used as default for deserialization, not null- Returns:
- new instance of serde with type changes
-
forKeys
Designate this Serde for serializing/deserializing keys (default is values).- Returns:
- the serde.
-
noTypeInfo
Configure the serializer to not add type information.- Returns:
- the serde.
-
dontRemoveTypeHeaders
Don't remove type information headers after deserialization.- Returns:
- the serde.
-
ignoreTypeHeaders
Ignore type information headers and use the configured target class.- Returns:
- the serde.
-
typeMapper
Use the suppliedJacksonJavaTypeMapper
.- Parameters:
mapper
- the mapper.- Returns:
- the serde.
-