Class JsonSerde<T>
java.lang.Object
org.springframework.kafka.support.serializer.JsonSerde<T>
- Type Parameters:
T
- target class for serialization/deserialization
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.apache.kafka.common.serialization.Serde<T>
A
Serde
that provides serialization and
deserialization in JSON format.
The implementation delegates to underlying JsonSerializer
and
JsonDeserializer
implementations.
- Since:
- 1.1.5
- Author:
- Marius Bogoevici, Elliot Kennedy, Gary Russell, Ivan Ponomarev
-
Constructor Summary
ConstructorDescriptionJsonSerde
(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
(JsonSerializer<T> jsonSerializer, JsonDeserializer<T> jsonDeserializer) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
<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
(Class<? super X> newTargetType) Copies this serde with same configuration, except new target 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
(Jackson2JavaTypeMapper mapper) Use the suppliedJackson2JavaTypeMapper
.
-
Constructor Details
-
JsonSerde
public JsonSerde() -
JsonSerde
-
JsonSerde
-
JsonSerde
-
JsonSerde
public JsonSerde(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
JsonSerde
-
JsonSerde
-
JsonSerde
-
JsonSerde
-
-
Method Details
-
configure
- Specified by:
configure
in interfaceorg.apache.kafka.common.serialization.Serde<T>
-
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
- 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
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
Designate this Serde for serializing/deserializing keys (default is values).- Returns:
- the serde.
- Since:
- 2.3
-
noTypeInfo
Configure the serializer to not add type information.- Returns:
- the serde.
- Since:
- 2.3
-
dontRemoveTypeHeaders
Don't remove type information headers after deserialization.- Returns:
- the serde.
- Since:
- 2.3
-
ignoreTypeHeaders
Ignore type information headers and use the configured target class.- Returns:
- the serde.
- Since:
- 2.3
-
typeMapper
Use the suppliedJackson2JavaTypeMapper
.- Parameters:
mapper
- the mapper.- Returns:
- the serde.
- Since:
- 2.3
-