Class JsonSerde<T>
- java.lang.Object
-
- org.springframework.kafka.support.serializer.JsonSerde<T>
-
- Type Parameters:
T
- target class for serialization/deserialization
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,org.apache.kafka.common.serialization.Serde<T>
public class JsonSerde<T> extends java.lang.Object implements org.apache.kafka.common.serialization.Serde<T>
ASerde
that provides serialization and deserialization in JSON format.The implementation delegates to underlying
JsonSerializer
andJsonDeserializer
implementations.- Since:
- 1.1.5
- Author:
- Marius Bogoevici, Elliot Kennedy, Gary Russell, Ivan Ponomarev
-
-
Constructor Summary
Constructors Constructor Description JsonSerde()
JsonSerde(com.fasterxml.jackson.core.type.TypeReference<? super T> targetType)
JsonSerde(com.fasterxml.jackson.core.type.TypeReference<? super T> targetType, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
JsonSerde(com.fasterxml.jackson.databind.JavaType targetType)
JsonSerde(com.fasterxml.jackson.databind.JavaType targetTypeArg, com.fasterxml.jackson.databind.ObjectMapper objectMapperArg)
JsonSerde(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
JsonSerde(java.lang.Class<? super T> targetType)
JsonSerde(java.lang.Class<? super T> targetType, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
JsonSerde(JsonSerializer<T> jsonSerializer, JsonDeserializer<T> jsonDeserializer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
configure(java.util.Map<java.lang.String,?> configs, boolean isKey)
<X> JsonSerde<X>
copyWithType(com.fasterxml.jackson.core.type.TypeReference<? super X> newTargetType)
Copies this serde with same configuration, except new target type reference is used.<X> JsonSerde<X>
copyWithType(com.fasterxml.jackson.databind.JavaType newTargetType)
Copies this serde with same configuration, except new target java type is used.<X> JsonSerde<X>
copyWithType(java.lang.Class<? super X> newTargetType)
Copies this serde with same configuration, except new target type is used.JsonDeserializer<T>
deserializer()
JsonSerde<T>
dontRemoveTypeHeaders()
Don't remove type information headers after deserialization.JsonSerde<T>
forKeys()
Designate this Serde for serializing/deserializing keys (default is values).JsonSerde<T>
ignoreTypeHeaders()
Ignore type information headers and use the configured target class.JsonSerde<T>
noTypeInfo()
Configure the serializer to not add type information.JsonSerializer<T>
serializer()
JsonSerde<T>
typeMapper(Jackson2JavaTypeMapper mapper)
Use the suppliedJackson2JavaTypeMapper
.
-
-
-
Constructor Detail
-
JsonSerde
public JsonSerde()
-
JsonSerde
public JsonSerde(@Nullable java.lang.Class<? super T> targetType)
-
JsonSerde
public JsonSerde(@Nullable com.fasterxml.jackson.core.type.TypeReference<? super T> targetType)
-
JsonSerde
public JsonSerde(@Nullable com.fasterxml.jackson.databind.JavaType targetType)
-
JsonSerde
public JsonSerde(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-
JsonSerde
public JsonSerde(@Nullable com.fasterxml.jackson.core.type.TypeReference<? super T> targetType, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-
JsonSerde
public JsonSerde(@Nullable java.lang.Class<? super T> targetType, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-
JsonSerde
public JsonSerde(@Nullable com.fasterxml.jackson.databind.JavaType targetTypeArg, @Nullable com.fasterxml.jackson.databind.ObjectMapper objectMapperArg)
-
JsonSerde
public JsonSerde(JsonSerializer<T> jsonSerializer, JsonDeserializer<T> jsonDeserializer)
-
-
Method Detail
-
configure
public void configure(java.util.Map<java.lang.String,?> configs, boolean isKey)
- Specified by:
configure
in interfaceorg.apache.kafka.common.serialization.Serde<T>
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceorg.apache.kafka.common.serialization.Serde<T>
-
serializer
public JsonSerializer<T> serializer()
- Specified by:
serializer
in interfaceorg.apache.kafka.common.serialization.Serde<T>
-
deserializer
public JsonDeserializer<T> deserializer()
- Specified by:
deserializer
in interfaceorg.apache.kafka.common.serialization.Serde<T>
-
copyWithType
public <X> JsonSerde<X> copyWithType(java.lang.Class<? super X> newTargetType)
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
- Since:
- 2.6
-
copyWithType
public <X> JsonSerde<X> copyWithType(com.fasterxml.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
- Since:
- 2.6
-
copyWithType
public <X> JsonSerde<X> copyWithType(com.fasterxml.jackson.databind.JavaType newTargetType)
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
- Since:
- 2.6
-
forKeys
public JsonSerde<T> forKeys()
Designate this Serde for serializing/deserializing keys (default is values).- Returns:
- the serde.
- Since:
- 2.3
-
noTypeInfo
public JsonSerde<T> noTypeInfo()
Configure the serializer to not add type information.- Returns:
- the serde.
- Since:
- 2.3
-
dontRemoveTypeHeaders
public JsonSerde<T> dontRemoveTypeHeaders()
Don't remove type information headers after deserialization.- Returns:
- the serde.
- Since:
- 2.3
-
ignoreTypeHeaders
public JsonSerde<T> ignoreTypeHeaders()
Ignore type information headers and use the configured target class.- Returns:
- the serde.
- Since:
- 2.3
-
typeMapper
public JsonSerde<T> typeMapper(Jackson2JavaTypeMapper mapper)
Use the suppliedJackson2JavaTypeMapper
.- Parameters:
mapper
- the mapper.- Returns:
- the serde.
- Since:
- 2.3
-
-