public class PrimitiveAvroSerde<T> extends Object implements org.apache.kafka.common.serialization.Serde<T>
A schema-registry aware serde (serializer/deserializer) for Apache Kafka's Streams API that can be used for reading and writing data of Avro primitive types.
The Avro primitive types (cf https://avro.apache.org/docs/current/spec.html#schema_primitive) are null, boolean, int, long, float, double, bytes, and string. Any other types aren't supported by this Serde.
This serde's "specific Avro" counterpart is SpecificAvroSerde and "generic Avro"
counterpart is GenericAvroSerde.
This serde reads and writes data according to the wire format defined at
http://docs.confluent.io/current/schema-registry/docs/serializer-formatter.html#wire-format. It
requires access to a Confluent Schema Registry endpoint, which you must configure(Map, boolean) via the parameter "schema.registry.url".
Usage
Example for configuring this serde as a Kafka Streams application's default serde for both record keys and record values:
Properties streamsConfiguration = new Properties();
streamsConfiguration.put(StreamsConfig.KEY_SERDE_CLASS_CONFIG, PrimitiveAvroSerde.class);
streamsConfiguration.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, PrimitiveAvroSerde.class);
streamsConfiguration.put(
AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
"http://confluent-schema-registry-server:8081/");
In practice, it's expected that the PrimitiveAvroSerde primary use case will be keys.
Example for explicitly overriding the application's default serdes (whatever they were
configured to) so that only specific operations such as KStream#to() use this serde:
Serde<Long> longAvroSerde = new PrimitiveAvroSerde<Long>();
boolean isKeySerde = true;
longAvroSerde.configure(
Collections.singletonMap(
AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
"http://confluent-schema-registry-server:8081/"),
isKeySerde);
Serde<GenericRecord> genericAvroSerde = new GenericAvroSerde();
isKeySerde = false;
genericAvroSerde.configure(
Collections.singletonMap(
AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
"http://confluent-schema-registry-server:8081/"),
isKeySerde);
KStream<Long, GenericRecord> stream = builder.stream("my-input-topic",
Consumed.with(longAvroSerde, genericAvroSerde));
| Constructor and Description |
|---|
PrimitiveAvroSerde() |
PrimitiveAvroSerde(SchemaRegistryClient client)
For testing purposes only.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
configure(Map<String,?> configs,
boolean isKey) |
org.apache.kafka.common.serialization.Deserializer<T> |
deserializer() |
org.apache.kafka.common.serialization.Serializer<T> |
serializer() |
public PrimitiveAvroSerde()
public PrimitiveAvroSerde(SchemaRegistryClient client)
public void configure(Map<String,?> configs, boolean isKey)
configure in interface org.apache.kafka.common.serialization.Serde<T>public void close()
close in interface Closeableclose in interface AutoCloseableclose in interface org.apache.kafka.common.serialization.Serde<T>public org.apache.kafka.common.serialization.Serializer<T> serializer()
serializer in interface org.apache.kafka.common.serialization.Serde<T>Copyright © 2026 Confluent, Inc.. All rights reserved.