Serialization & Schema Registries

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

A change event is a structure in memory until a converter turns it into bytes. The choice of converter decides how big each message is, whether a consumer can tell a Decimal from a string, and what happens when someone adds a column to the legacy Oracle table. In a migration that runs for months, the last point matters most. Every DDL change in the legacy database produces a new event schema, and the serialization format decides whether that change is checked, versioned and visible to the new application, or simply appears in the next message.

This page explains the options that Debezium documents: the Kafka Connect JSON converter with and without embedded schemas, Avro with Apicurio Registry, Avro with Confluent Schema Registry, the Avro naming rules, the Debezium JSON SerDe for consumers, and the CloudEvents converter, with two Java consumers of the legacy.BOOKSHOP.BOOK topic. The canonical Bookshop source connector bookshop-oracle-source uses the JSON converter with schemas enabled and decimal.handling.mode=string, and no Avro. Avro with Apicurio Registry is shown on this page as the alternative for pipelines that need versioned schemas and compatibility checks. The structure of the event itself is described in Anatomy of a Change Event. The general concepts of serializers, schema registries and compatibility modes are on the messaging page Kafka Serialization and Schemas, which this page does not repeat.

Checked on 2026-11-09 against Debezium 3.7.1.Final, Apicurio Registry 3.3.4 (released 2026-11-03; the quay.io/debezium/connect:3.7.1.Final image bundles the Apicurio 3.2.5 converters, and the Debezium Avro page uses the apicurio/apicurio-registry:3.2.5 image in its example), Confluent Schema Registry 8.4.0 (confluentinc/cp-schema-registry:8.4.0) and Kafka clients 4.3.1. What was actually run: the two Java consumers on this page were compiled against these versions, the JSON SerDe was run against the example events (with decimal.handling.mode=string) from Anatomy of a Change Event, and the registry calls on this page were run with Docker on 2026-11-09 against an Apicurio Registry 3.3.4 container: the global rule set by environment variable, the v2 and v3 APIs, the rejection of a new required field under BACKWARD and the artifact rule override. The canonical JSON configuration was run end to end in the worked example. The Avro and CloudEvents connector configurations were derived from the official documentation and were not run against Oracle.

Where serialization happens

A Debezium source connector produces Kafka Connect records: a key, a value, their Kafka Connect schemas and some headers. For each record, Kafka Connect then:

  1. applies the configured single message transformations (SMTs),

  2. serializes the key and the value with the configured converters, and

  3. writes the bytes to the topic.

Converters are configured at two levels:

  • on the worker, as defaults for every connector (key.converter, value.converter in the worker configuration, or the KEY_CONVERTER / VALUE_CONVERTER environment variables of the Debezium Connect image), and

  • on the connector, with the same property names in the connector configuration, which override the worker defaults for that connector only.

Kafka Connect always stores its own configuration, offsets and status in its internal topics with JSON, whatever converters the connectors use. The schema history topic of the Oracle connector (legacy.schema-history) is also written by the connector itself, not through the converters.

Converter options are passed with the converter’s prefix: value.converter.schemas.enable reaches the value converter as schemas.enable, value.converter.apicurio.registry.url reaches it as apicurio.registry.url.

The following diagram shows where each format puts the schema.

flowchart LR DBZ["Oracle connector: record with Connect schema"] --> SMT["SMTs"] SMT --> CONV{"Converter"} CONV -->|"JSON, schemas.enable=true"| J1["Message: schema plus payload"] CONV -->|"JSON, schemas.enable=false"| J2["Message: payload only, no types"] CONV -->|"Avro"| A1["Message: schema ID plus binary payload"] A1 -.->|"schema registered by ID"| REG[("Schema registry")] CONV -->|"CloudEvents"| C1["Message: CloudEvents envelope with data"]

JSON with and without schemas

The Debezium Connect image uses org.apache.kafka.connect.json.JsonConverter by default. With its default setting, schemas.enable=true, every message is a JSON object with two members, schema and payload. The schema describes every field, including the logical types that consumers need to decode the payload: org.apache.kafka.connect.data.Decimal with its scale, io.debezium.time.Timestamp, and so on. For a table like BOOK, the schema repeats the ten column definitions for before and after and adds the source schema, so it is several times larger than the payload.

Debezium’s Avro page suggests setting key.converter.schemas.enable and value.converter.schemas.enable to false when you use JSON and do not need the schema, which leaves only the payload.

JSON converter without embedded schemas (generic connector fragment, not used by the Bookshop source)
{
  "key.converter": "org.apache.kafka.connect.json.JsonConverter",
  "key.converter.schemas.enable": "false",
  "value.converter": "org.apache.kafka.connect.json.JsonConverter",
  "value.converter.schemas.enable": "false"
}

For a database migration, the decision is not only about size:

Option What consumers get Use it when

JSON with schemas

Self-describing messages. Decimals and temporal types can be decoded. Large messages.

You feed the Debezium JDBC sink or another consumer that needs types, and you do not want to run a registry. The canonical Bookshop setting.

JSON without schemas

Small, readable payloads. Type information is lost: with decimal.handling.mode=precise, NUMBER(10,2) arrives as a base64 string with no scale.

Consumers are your own code, they know the legacy types, and you set decimal.handling.mode=string or use the ExtractNewRecordState SMT to produce simple values.

Avro with a registry

Small binary messages with a schema ID. Types are kept. Schema changes are versioned and checked.

Production pipelines, long-running migrations, many consumers, and any pipeline in which schema changes in the legacy database must not surprise consumers.

The Debezium JDBC sink connector needs the schema to recognize the Debezium envelope: with schemaless JSON it stays RUNNING and skips every record with "isn’t a Debezium record". The Bookshop pipeline therefore uses JSON with schemas for both the key and the value of bookshop-oracle-source, which bookshop-pg-mirror-sink reads. Avro would work as well. See JDBC Sink Connector.

JSON converter with embedded schemas (the canonical bookshop-oracle-source setting)
{
  "key.converter": "org.apache.kafka.connect.json.JsonConverter",
  "key.converter.schemas.enable": "true",
  "value.converter": "org.apache.kafka.connect.json.JsonConverter",
  "value.converter.schemas.enable": "true"
}

These are also the defaults of the quay.io/debezium/connect image, so setting them in the connector only makes the choice explicit.

Avro and why a registry is needed

Apache Avro is a compact binary format whose messages carry no field names: a reader can only decode a message if it has the schema that the writer used. A schema registry solves this. The converter registers the schema of each key and value in the registry, receives an ID, and writes only that ID with the binary data. The consumer reads the ID, fetches the schema from the registry (once, then from a cache) and decodes the message.

For Debezium this has three consequences that matter in a migration:

  • Messages are much smaller than JSON with schemas, which matters during an initial snapshot of millions of rows.

  • Every schema change in the legacy table becomes a new version in the registry, so you can list the history of legacy.BOOKSHOP.BOOK and see when a column appeared.

  • The registry can apply compatibility rules and reject a schema change that would break consumers. This is the only point in the pipeline where a dangerous DDL change can be stopped automatically. See Compatibility rules and legacy DDL.

Debezium documents two registries: Apicurio Registry and Confluent Schema Registry.

Avro with Apicurio Registry

Apicurio Registry is an open-source registry for schemas and API definitions. For Debezium it provides an Avro converter for Kafka Connect (io.apicurio.registry.utils.converter.AvroConverter), the registry itself, and Avro SerDes for Kafka producers and consumers (io.apicurio.registry.serde.avro.AvroKafkaSerializer and io.apicurio.registry.serde.avro.AvroKafkaDeserializer). The project also provides a JSON converter that writes JSON payloads with only a schema ID, which keeps messages readable without embedding the schema.

Running the registry with the Debezium containers

The quay.io/debezium/connect image already contains the Apicurio converters. They are disabled by default and are added to the plug-in path when the container starts with ENABLE_APICURIO_CONVERTERS=true. The following Compose file runs Kafka, Kafka Connect and Apicurio Registry for the Bookshop pipeline. The Oracle service is defined on Oracle Connector. This file only adds the serialization side.

compose.yaml: Kafka, Kafka Connect with Apicurio converters, Apicurio Registry
services:
  kafka:
    image: quay.io/debezium/kafka:3.7.1.Final
    ports:
      - "9092:9094"    # host clients use localhost:9092
    environment:
      - CLUSTER_ID=oh-sxaDRTcyAr6pFRbXyzA
      - NODE_ID=1
      - NODE_ROLE=combined
      - KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka:9093
      - KAFKA_LISTENERS=PLAINTEXT://kafka:9092,CONTROLLER://kafka:9093,HOST://0.0.0.0:9094
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,HOST://localhost:9092
      - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT,HOST:PLAINTEXT

  apicurio:
    image: apicurio/apicurio-registry:3.3.4
    ports:
      - "8080:8080"
    environment:
      # Default global rule: every new schema version must be backward compatible
      - APICURIO_RULES_GLOBAL_COMPATIBILITY=BACKWARD

  connect:
    image: quay.io/debezium/connect:3.7.1.Final
    ports:
      - "8083:8083"
    depends_on:
      - kafka
      - apicurio
    environment:
      - BOOTSTRAP_SERVERS=kafka:9092
      - GROUP_ID=bookshop-connect
      - CONFIG_STORAGE_TOPIC=bookshop_connect_configs
      - OFFSET_STORAGE_TOPIC=bookshop_connect_offsets
      - STATUS_STORAGE_TOPIC=bookshop_connect_statuses
      - ENABLE_APICURIO_CONVERTERS=true

A few details are easy to miss:

  • The registry in this file keeps its data in memory (the image’s default storage), so every restart loses all schemas and their IDs, while the Kafka topics still contain messages with the old IDs. For anything longer than a lab, run the registry with persistent storage (the sql or kafkasql storage kinds in the Apicurio configuration reference). Losing the registry during a migration makes every message on every Avro topic unreadable.

  • APICURIO_RULES_GLOBAL_COMPATIBILITY is the environment variable form of the Apicurio property apicurio.rules.global.compatibility. It sets a default global rule. Without any rule, Apicurio applies no checks.

  • Kafka has two client listeners. Containers in the Compose network (Kafka Connect, the connector’s schema history client) use kafka:9092. Programs on the host, such as the Java consumers below, use localhost:9092, which Docker forwards to the HOST listener on container port 9094. A broker advertises the address of the listener a client connected to, so each side gets an address that it can reach. This listener layout was checked with a Kafka admin client against the quay.io/debezium/kafka:3.7.1.Final image.

Configuring the connector for Avro

The canonical Bookshop pipeline does not use Avro. If a migration needs the registry, set the Apicurio converter for the key and the value in the connector configuration. The following PUT replaces the whole configuration of bookshop-oracle-source, so it repeats the canonical connection, capture and signaling properties from Oracle Connector and adds the converter properties at the end. Do this before the initial snapshot (see Choosing a format for the migration).

Alternative: run bookshop-oracle-source with Avro and Apicurio Registry
curl -s -X PUT -H "Content-Type: application/json" \
  http://localhost:8083/connectors/bookshop-oracle-source/config \
  -d '{
    "connector.class": "io.debezium.connector.oracle.OracleConnector",
    "tasks.max": "1",
    "database.hostname": "oracle",
    "database.port": "1521",
    "database.user": "c##dbzuser",
    "database.password": "dbz",
    "database.dbname": "FREE",
    "database.pdb.name": "FREEPDB1",
    "topic.prefix": "legacy",
    "table.include.list": "BOOKSHOP.BOOK,BOOKSHOP.AUTHOR,BOOKSHOP.CUSTOMER,BOOKSHOP.ORDERS,BOOKSHOP.ORDER_LINE,BOOKSHOP.SUPPLIER_CATALOGUE",
    "decimal.handling.mode": "string",
    "provide.transaction.metadata": "true",
    "schema.history.internal.kafka.bootstrap.servers": "kafka:9092",
    "schema.history.internal.kafka.topic": "legacy.schema-history",
    "schema.history.internal.store.only.captured.tables.ddl": "false",
    "signal.enabled.channels": "source,kafka",
    "signal.data.collection": "FREEPDB1.BOOKSHOP.DEBEZIUM_SIGNAL",
    "signal.kafka.topic": "legacy.signals",
    "signal.kafka.bootstrap.servers": "kafka:9092",

    "key.converter": "io.apicurio.registry.utils.converter.AvroConverter",
    "key.converter.apicurio.registry.url": "http://apicurio:8080/apis/registry/v3",
    "key.converter.apicurio.registry.auto-register": "true",
    "key.converter.apicurio.registry.find-latest": "true",
    "value.converter": "io.apicurio.registry.utils.converter.AvroConverter",
    "value.converter.apicurio.registry.url": "http://apicurio:8080/apis/registry/v3",
    "value.converter.apicurio.registry.auto-register": "true",
    "value.converter.apicurio.registry.find-latest": "true",
    "schema.name.adjustment.mode": "avro",
    "field.name.adjustment.mode": "avro"
  }'

What each converter property does:

apicurio.registry.url

The registry’s REST API. Apicurio Registry 3.x documents the v3 path /apis/registry/v3. The Debezium page shows /apis/registry/v2, the older core API that Apicurio Registry 3.x still serves for compatibility, and the 3.x client libraries include a v2 client. New installations should use the v3 path. Inside the Compose network the host name is apicurio. From the host it is http://localhost:8080.

apicurio.registry.auto-register

Lets the converter register a new schema (or a new version) when it sees one. It defaults to false. Debezium generates schemas from the table structure at run time, so without auto-registration every DDL change would stop the connector until someone registers the schema by hand. Some teams want exactly that for production; most enable it and rely on compatibility rules.

apicurio.registry.find-latest

Makes the converter look up the latest version of an artifact. It defaults to false.

schema.name.adjustment.mode and field.name.adjustment.mode

Debezium connector properties, not converter properties. avro replaces characters that are not valid in Avro names with underscores (see Avro naming rules).

Apicurio stores each schema as an artifact in a group. With the default artifact resolver strategy, io.apicurio.registry.serde.strategy.TopicIdStrategy, the artifact ID is the topic name followed by -key or -value, so the BOOK table produces the artifacts legacy.BOOKSHOP.BOOK-key and legacy.BOOKSHOP.BOOK-value.

Confluent compatibility mode

Consumers that use Confluent’s Avro deserializer expect Confluent’s wire format: a magic byte followed by a 4-byte schema ID. Apicurio’s converter can write that format, which lets a team keep Confluent-based consumers while running Apicurio Registry. The Debezium page lists these converter properties for that mode.

Apicurio converter in Confluent compatibility mode (alternative Avro connector fragment)
{
  "key.converter": "io.apicurio.registry.utils.converter.AvroConverter",
  "key.converter.apicurio.registry.url": "http://apicurio:8080/apis/registry/v3",
  "key.converter.apicurio.registry.auto-register": "true",
  "key.converter.apicurio.registry.find-latest": "true",
  "key.converter.schemas.enable": "false",
  "key.converter.apicurio.registry.headers.enabled": "false",
  "key.converter.apicurio.registry.as-confluent": "true",
  "key.converter.apicurio.use-id": "contentId",
  "value.converter": "io.apicurio.registry.utils.converter.AvroConverter",
  "value.converter.apicurio.registry.url": "http://apicurio:8080/apis/registry/v3",
  "value.converter.apicurio.registry.auto-register": "true",
  "value.converter.apicurio.registry.find-latest": "true",
  "value.converter.schemas.enable": "false",
  "value.converter.apicurio.registry.headers.enabled": "false",
  "value.converter.apicurio.registry.as-confluent": "true",
  "value.converter.apicurio.use-id": "contentId",
  "schema.name.adjustment.mode": "avro"
}

as-confluent switches to the Confluent wire format, use-id writes only a numeric ID, schemas.enable=false keeps the full schema out of the message, and headers.enabled=false stops the converter from writing Apicurio-specific headers that Confluent clients would not understand. Choose one wire format for the whole migration. Mixing formats on one topic makes some messages unreadable for some consumers.

Inspecting the registered schemas

After the snapshot starts, the registry contains one key and one value artifact per captured table. The v3 REST API lets you check this from a shell.

List the Bookshop artifacts and the versions of the BOOK value schema
# All artifacts whose ID starts with the topic prefix
curl -s "http://localhost:8080/apis/registry/v3/search/artifacts?limit=50" | jq '.artifacts[].artifactId'

# Versions of the BOOK value schema (one per change of the legacy table structure)
curl -s "http://localhost:8080/apis/registry/v3/groups/default/artifacts/legacy.BOOKSHOP.BOOK-value/versions" | jq

# The global rules that apply to every artifact
curl -s "http://localhost:8080/apis/registry/v3/admin/rules"
curl -s "http://localhost:8080/apis/registry/v3/admin/rules/COMPATIBILITY"

The last call returns {"config":"BACKWARD","ruleType":"COMPATIBILITY"} with the Compose file above. Artifacts that the converter registers without a group are placed in the group default.

Avro with Confluent Schema Registry

Since Debezium 2.0 the Debezium container images no longer include the Confluent Avro converter. To use Confluent Schema Registry, add the converter JARs to a plug-in directory of the Connect image: kafka-connect-avro-converter, kafka-connect-avro-data, kafka-avro-serializer, kafka-schema-serializer, kafka-schema-converter, kafka-schema-registry-client, common-config and common-utils from the Confluent Maven repository, and their dependencies (avro, commons-compress, failureaccess, guava, minimal-json, re2j, slf4j-api, snakeyaml, swagger-annotations, the three Jackson JARs, jackson-dataformat-csv, logredactor and logredactor-metrics) from Maven Central. The usual way is a small derived image that copies the JARs into a directory under /kafka/connect. Check the Confluent licence terms for the components you add.

compose.yaml service for Confluent Schema Registry
services:
  schema-registry:
    image: confluentinc/cp-schema-registry:8.4.0
    ports:
      - "8081:8081"
    depends_on:
      - kafka
    environment:
      - SCHEMA_REGISTRY_HOST_NAME=schema-registry
      - SCHEMA_REGISTRY_LISTENERS=http://0.0.0.0:8081
      - SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS=kafka:9092

The docker run example on the Debezium page publishes port 8181 while the registry listens on 8081. The service above publishes the port that the registry actually listens on.

Confluent Avro converter (alternative Avro connector fragment)
{
  "key.converter": "io.confluent.connect.avro.AvroConverter",
  "key.converter.schema.registry.url": "http://schema-registry:8081",
  "value.converter": "io.confluent.connect.avro.AvroConverter",
  "value.converter.schema.registry.url": "http://schema-registry:8081",
  "schema.name.adjustment.mode": "avro"
}

Confluent Schema Registry names its subjects <topic>-key and <topic>-value by default, like Apicurio’s TopicIdStrategy, and its default compatibility level is BACKWARD. The registry’s own documentation describes how to change the level per subject. To read Avro messages from a shell, the Debezium page uses the Kafka console consumer with io.confluent.kafka.formatter.AvroMessageFormatter, which needs the Confluent JARs on the class path.

Avro naming rules

Avro names must start with a letter or an underscore and contain only letters, digits and underscores. Debezium uses table and column names to build schema and field names, so legacy names can break Avro serialization. Oracle allows $ and # in unquoted identifiers, and legacy schemas use them more often than you would expect (for example a column named UPD$USER or REF#). A quoted identifier can contain almost anything.

Two connector properties fix this without touching the legacy schema:

Property Default Values

schema.name.adjustment.mode

none

none (no change), avro (replace invalid characters in schema names with _), avro_unicode (replace them with a _uxxxx escape, so that different names stay different).

field.name.adjustment.mode

none

The same values, applied to field (column) names.

Set both to avro for Avro pipelines. Use avro_unicode if two legacy names differ only in invalid characters (PRICE$ and PRICE# would both become PRICE_ with avro, and the second would collide with the first). The adjusted names are the names that consumers and the JDBC sink see, so a column UPD$USER arrives in the mirror table as upd_user. Record such renames in the mapping documentation for the new model.

Compatibility rules and legacy DDL

Every change to the structure of a captured legacy table changes the event schema. With auto-registration enabled, the converter registers the new schema as a new version of the artifact, and the registry checks it against the compatibility rule. If the check fails, the registry rejects the schema, the converter throws an exception, and the connector task fails. Nothing is written to the topic, and the connector stays in the FAILED state until the schema is accepted or the rule changes. This is a feature: it stops a breaking change at the source instead of in every consumer. But it must be planned, because while the task is failed the legacy changes are not captured, and the redo logs that hold them must stay available until it resumes.

The table shows how common legacy DDL changes look to a registry with Avro, given that Debezium makes nullable columns optional fields (a union with null and a null default) and NOT NULL columns required fields.

DDL in the legacy database Change in the Avro schema Result

ADD a nullable column

New optional field with a default

Compatible both ways (BACKWARD, FORWARD, FULL).

DROP a nullable column

Optional field removed

Compatible both ways.

ADD a NOT NULL column without a default

New required field

Not BACKWARD compatible: the new schema cannot read old data that lacks the field. Apicurio Registry rejects the new version with HTTP 400 under a BACKWARD rule.

MODIFY a column from nullable to NOT NULL

Optional field becomes required

Not BACKWARD compatible.

RENAME COLUMN

One field removed, another added

Usually accepted if both are optional, but consumers silently lose the old field. Treat it as a breaking change.

Change NUMBER(10,2) to NUMBER(12,2) or change the scale

The parameters of the Decimal logical type change

Depends on how the registry compares logical types. Test the change against the registry before the DDL ships.

Choose the rule from the consumers' point of view. Consumers that use Avro GenericRecord (like the Apicurio consumer below) always decode with the writer’s schema, which they fetch by ID, so they cope with any registered schema but may miss fields they expect. Consumers that compile classes from a schema (Avro SpecificRecord) decode with their own reader schema and need the rule to guarantee that they can read what the connector writes next. BACKWARD (the Confluent default) or FULL are the usual choices for CDC topics.

The safe way to change a legacy table during a migration is expand/contract: add the new column as nullable, migrate the data, and only then tighten it, as described in Evolving the Database Model — Best Practices. When a breaking change cannot be avoided, relax the rule for that one artifact, let the connector register the new version, and restore the rule. Apicurio applies an artifact rule in place of the global rule of the same type.

Relax and restore the compatibility rule for the BOOK value schema (Apicurio v3 API)
# Allow the next version of legacy.BOOKSHOP.BOOK-value regardless of compatibility
curl -s -X POST -H "Content-Type: application/json" \
  "http://localhost:8080/apis/registry/v3/groups/default/artifacts/legacy.BOOKSHOP.BOOK-value/rules" \
  -d '{"ruleType": "COMPATIBILITY", "config": "NONE"}'

# Restart the failed task so that the converter registers the new schema
curl -s -X POST "http://localhost:8083/connectors/bookshop-oracle-source/restart?includeTasks=true&onlyFailed=true"

# Remove the artifact rule again, so the global BACKWARD rule applies
curl -s -X DELETE \
  "http://localhost:8080/apis/registry/v3/groups/default/artifacts/legacy.BOOKSHOP.BOOK-value/rules/COMPATIBILITY"

The full process for schema changes during the migration, including the schema history topic and the JDBC sink’s schema.evolution setting, is in Handling Schema Changes.

Reading Avro events in Java

A consumer reads Apicurio-encoded events with AvroKafkaDeserializer from the io.apicurio:apicurio-registry-avro-serde-kafka artifact. Without further configuration it returns Avro GenericRecord objects decoded with the writer’s schema.

Maven dependencies for the Avro consumer
<dependencies>
  <dependency>
    <groupId>io.apicurio</groupId>
    <artifactId>apicurio-registry-avro-serde-kafka</artifactId>
    <version>3.3.4</version>
  </dependency>
  <dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>4.3.1</version>
  </dependency>
</dependencies>
LegacyBookAvroReader.java: read Avro change events of BOOK
package com.example.bookshop.migration;

import io.apicurio.registry.serde.avro.AvroKafkaDeserializer;
import io.apicurio.registry.serde.config.SerdeConfig;
import org.apache.avro.generic.GenericRecord;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.KafkaConsumer;

import java.time.Duration;
import java.util.List;
import java.util.Properties;

/**
 * Reads Avro-encoded change events from legacy.BOOKSHOP.BOOK. The writer schema of each record
 * is fetched from Apicurio Registry by the ID that the converter wrote into the record.
 */
public final class LegacyBookAvroReader {

    public static void main(String[] args) {
        Properties props = new Properties();
        props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
        props.put(ConsumerConfig.GROUP_ID_CONFIG, "bookshop-avro-demo");
        props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
        props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, AvroKafkaDeserializer.class.getName());
        props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, AvroKafkaDeserializer.class.getName());
        props.put(SerdeConfig.REGISTRY_URL, "http://localhost:8080/apis/registry/v3");

        try (KafkaConsumer<GenericRecord, GenericRecord> consumer = new KafkaConsumer<>(props)) {
            consumer.subscribe(List.of("legacy.BOOKSHOP.BOOK"));
            while (true) {
                for (ConsumerRecord<GenericRecord, GenericRecord> rec : consumer.poll(Duration.ofSeconds(1))) {
                    GenericRecord envelope = rec.value();
                    if (envelope == null) {
                        continue; // tombstone
                    }
                    GenericRecord after = (GenericRecord) envelope.get("after");
                    GenericRecord source = (GenericRecord) envelope.get("source");
                    System.out.printf("op=%s BOOK_ID=%s scn=%s after=%s%n",
                            envelope.get("op"), rec.key().get("BOOK_ID"), source.get("scn"), after);
                }
            }
        }
    }
}

SerdeConfig.REGISTRY_URL is the constant for apicurio.registry.url. In a Spring Boot 4.1 application with Spring for Apache Kafka, the same settings go into application.yml.

application.yml: Apicurio Avro deserializer in the Spring Boot bookshop application
spring:
  kafka:
    bootstrap-servers: localhost:9092
    consumer:
      group-id: bookshop-legacy-sync
      auto-offset-reset: earliest
      key-deserializer: io.apicurio.registry.serde.avro.AvroKafkaDeserializer
      value-deserializer: io.apicurio.registry.serde.avro.AvroKafkaDeserializer
      properties:
        apicurio.registry.url: http://localhost:8080/apis/registry/v3

With decimal.handling.mode=string, the canonical setting, PRICE and the identifiers are Avro string fields and the consumer parses them. If an Avro pipeline uses precise instead, the PRICE column (NUMBER(10,2)) is a bytes field with the decimal logical type, precision 10 and scale 2. A GenericRecord returns it as a ByteBuffer unless the deserializer is configured with Avro’s decimal conversion, so decode it with the scale from the schema. The listeners, error handling and idempotency of the real bookshop application are on Listening to Events in Applications and Spring Boot and Kafka.

The Debezium JSON SerDe

For consumers that read JSON-encoded events (with or without schemas), Debezium provides SerDes in io.debezium.serde.DebeziumSerdes. They work as plain Kafka deserializers and as Kafka Streams Serde instances. The feature is incubating: its semantics and options may change. DebeziumSerdes.payloadJson(Class) creates a SerDe that maps the JSON with Jackson Databind into the given class. Its behaviour:

  • If the message contains schema and payload, only the payload is used, so the same code works with schemas.enable on and off.

  • For keys, the key fields are mapped into the target class. A single-field key such as BOOK_ID can be read as a plain value: a String with the canonical decimal.handling.mode=string (the key is {"BOOK_ID":"1001"}), a Long with precise.

  • For values, from.field selects what is mapped: empty for the whole envelope, before or after for one image. This flattens the event in the consumer.

  • A value that is already flattened (by the ExtractNewRecordState SMT) is mapped directly.

Option Default Meaning

from.field

none

Empty to map the whole envelope, before or after to map only that image.

unknown.properties.ignored

false

Whether unknown JSON properties are ignored. With false, a new column in the legacy table makes the deserializer throw, which is a cheap way to notice schema changes, and a way to stop a consumer at an awkward moment.

In Debezium 3.7 the class is in the io.debezium:debezium-connector-common artifact (the debezium-core artifact is now an aggregator without classes of its own). The Kafka client and connect-json classes are provided dependencies of that artifact, so add them yourself.

Maven dependencies for the JSON SerDe consumer
<dependencies>
  <dependency>
    <groupId>io.debezium</groupId>
    <artifactId>debezium-connector-common</artifactId>
    <version>3.7.1.Final</version>
  </dependency>
  <dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>4.3.1</version>
  </dependency>
  <dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>connect-json</artifactId>
    <version>4.3.1</version>
  </dependency>
</dependencies>

The record below describes a row of the legacy BOOK table as it appears in the after image with the canonical decimal.handling.mode=string. Every NUMBER column is a JSON string, which the record keeps as text and parses in its accessors, and the Oracle DATE values are turned into local dates and times.

LegacyBook.java: the BOOK row as the JSON SerDe maps it
package com.example.bookshop.migration;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * One row of the legacy BOOKSHOP.BOOK table, as it appears in the "after" (or "before")
 * image of a change event from bookshop-oracle-source: decimal.handling.mode=string, so every
 * NUMBER column is a JSON string, and the default time.precision.mode.
 */
public record LegacyBook(
        @JsonProperty("BOOK_ID") String bookId,          // NUMBER(10) as a string, for example "1001"
        @JsonProperty("ISBN") String isbn,
        @JsonProperty("TITLE") String title,
        @JsonProperty("AUTHOR_ID") String authorId,
        @JsonProperty("PRICE") String priceText,         // NUMBER(10,2) as an exact string, for example "22.50"
        @JsonProperty("CURRENCY") String currency,
        @JsonProperty("PUBLISHED") Long publishedMillis, // io.debezium.time.Timestamp
        @JsonProperty("ACTIVE_FLG") String activeFlag,
        @JsonProperty("SUPPLIER_ID") String supplierId,
        @JsonProperty("LAST_UPD") Long lastUpdatedMillis) {

    public long id() {
        return Long.parseLong(bookId.trim());
    }

    public BigDecimal price() {
        return priceText == null ? null : new BigDecimal(priceText.trim());
    }

    public LocalDate publishedOn() {
        return publishedMillis == null ? null
                : LocalDateTime.ofInstant(Instant.ofEpochMilli(publishedMillis), ZoneOffset.UTC).toLocalDate();
    }

    public LocalDateTime lastUpdatedLocal() {
        return lastUpdatedMillis == null ? null
                : LocalDateTime.ofInstant(Instant.ofEpochMilli(lastUpdatedMillis), ZoneOffset.UTC);
    }

    public boolean active() {
        return "Y".equals(activeFlag);
    }
}
LegacyBookReader.java: a plain Kafka consumer with the Debezium JSON SerDe
package com.example.bookshop.migration;

import io.debezium.serde.DebeziumSerdes;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.Serde;

import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * Reads the "after" image of every change on legacy.BOOKSHOP.BOOK with the Debezium JSON SerDe.
 * Delete events have no "after" image and tombstones have no value, so both arrive as null.
 */
public final class LegacyBookReader {

    public static void main(String[] args) {
        Serde<String> keySerde = DebeziumSerdes.payloadJson(String.class);
        keySerde.configure(Map.of(), true);

        Serde<LegacyBook> valueSerde = DebeziumSerdes.payloadJson(LegacyBook.class);
        valueSerde.configure(Map.of("from.field", "after", "unknown.properties.ignored", "true"), false);

        Properties props = new Properties();
        props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
        props.put(ConsumerConfig.GROUP_ID_CONFIG, "bookshop-serde-demo");
        props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

        try (KafkaConsumer<String, LegacyBook> consumer =
                     new KafkaConsumer<>(props, keySerde.deserializer(), valueSerde.deserializer())) {
            consumer.subscribe(List.of("legacy.BOOKSHOP.BOOK"));
            while (true) {
                for (ConsumerRecord<String, LegacyBook> rec : consumer.poll(Duration.ofSeconds(1))) {
                    LegacyBook book = rec.value();
                    if (book == null) {
                        System.out.printf("BOOK_ID %s deleted (delete event or tombstone)%n", rec.key());
                    } else {
                        System.out.printf("BOOK_ID %d: %s, %s %s, published %s, active %s%n",
                                book.id(), book.title(), book.price(), book.currency(),
                                book.publishedOn(), book.active());
                    }
                }
            }
        }
    }
}

Fed with the update event from Anatomy of a Change Event, the key deserializer returns "1001" and the value deserializer returns a LegacyBook with id() equal to 1001, price() equal to 22.50, publishedOn() equal to 2019-05-14 and lastUpdatedLocal() equal to 2026-11-09T10:42:07, with and without the embedded schema. For the delete event it returns null, because from.field=after selects the after image, which is null. A consumer that must tell a delete from a tombstone, or must see op, needs a class for the whole envelope (leave from.field empty) instead.

The string form carries its own scale, so a change of the legacy column to NUMBER(12,3) reaches the consumer as "22.500" and is still parsed correctly. With the default precise mode the same consumer would need the scale to decode a base64 value, and a hard-coded scale would decode wrong prices without any error after such a change. See Data Types & Precision.

CloudEvents

CloudEvents is a CNCF specification for describing events in a common way, with standard attributes (id, source, specversion, type, time, datacontenttype) and rules for custom extension attributes. Debezium provides io.debezium.converters.CloudEventsConverter, a Kafka Connect converter that wraps each change event in a CloudEvent. It is supported for the Db2, Informix, MongoDB, MySQL, Oracle, PostgreSQL and SQL Server connectors, and it is incubating. Only the structured mode is supported: the envelope and the data attribute can each be JSON or Avro.

CloudEvents are useful in a migration when the change events leave the Kafka-centred pipeline, for example when an event router, a serverless function or another platform consumes them and expects CloudEvents. For the JDBC sink and the Bookshop consumers, plain Debezium events are simpler.

CloudEvents converter with a JSON envelope and JSON data (alternative connector fragment)
{
  "value.converter": "io.debezium.converters.CloudEventsConverter",
  "value.converter.serializer.type": "json",
  "value.converter.data.serializer.type": "json"
}

The converter maps the source fields to extension attributes with the prefix iodebezium, sets type to io.debezium.connector.oracle.DataChangeEvent, sets source to /debezium/oracle/legacy (the connector type and topic.prefix), generates id from the event content and puts the row images into data. The example below is abridged: the converter adds one iodebezium attribute for each field of the source block.

A BOOK update as a CloudEvent (abridged)
{
  "id": "generated-by-the-converter-from-the-event-position",
  "source": "/debezium/oracle/legacy",
  "specversion": "1.0",
  "type": "io.debezium.connector.oracle.DataChangeEvent",
  "time": "2026-11-09T10:42:07Z",
  "datacontenttype": "application/json",
  "iodebeziumop": "u",
  "iodebeziumversion": "3.7.1.Final",
  "iodebeziumconnector": "oracle",
  "iodebeziumname": "legacy",
  "iodebeziumsnapshot": "false",
  "iodebeziumdb": "FREEPDB1",
  "iodebeziumschema": "BOOKSHOP",
  "iodebeziumtable": "BOOK",
  "iodebeziumtxid": "0a001f00c3020000",
  "iodebeziumscn": "4815162",
  "data": {
    "before": { "BOOK_ID": "1001", "PRICE": "24.99" },
    "after": { "BOOK_ID": "1001", "PRICE": "22.50" }
  }
}

The most useful converter options:

Option Default Meaning

serializer.type

json

Encoding of the envelope: json or avro.

data.serializer.type

json

Encoding of the data attribute: json or avro. With Avro, pass the registry settings with the avro. prefix, for example avro.schema.registry.url.

metadata.source

value,id:generate,type:generate,traceparent:header,dataSchemaName:generate

Where the converter takes the metadata from (value or header) and whether id, type, traceparent and the data schema name are generated or read from headers. After the outbox router, the metadata is no longer in the value and must be copied into headers first.

extension.attributes.enable

true

Whether the iodebezium extension attributes are added.

opentelemetry.tracing.attributes.enable

false

Whether the traceparent attribute is included.

schema.cloudevents.name

none

The schema name for the envelope in a registry when serializer.type is avro.

The converter works on record values only. Keep a normal key converter (JSON or Avro) so that partitioning and compaction by BOOK_ID still work.

Choosing a format for the migration

Concern JSON with schemas JSON without schemas Avro with a registry

Message size during the snapshot

Largest

Small

Smallest

Types (Decimal, timestamps) available to consumers

Yes

No

Yes

Works with the Debezium JDBC sink

Yes

No

Yes

Schema history and compatibility checks

No

No

Yes

Extra infrastructure

None

None

A registry with persistent storage

Human-readable on the topic

Yes

Yes

Needs a registry-aware tool

The Bookshop pipeline uses JSON with schemas for the legacy.* topics, with decimal.handling.mode=string: it needs no extra infrastructure, the JDBC sink reads it, and the hand-written consumers parse readable values. A migration with many consumer teams, frequent legacy DDL changes or high snapshot volumes should consider Avro with Apicurio Registry instead, with a BACKWARD global rule, persistent registry storage, and both name adjustment modes set to avro. Whatever you choose, choose it before the initial snapshot: changing the converter of a running connector leaves old-format messages on the topics, and every consumer must then read both formats until those messages expire.