Debezium Event Deserialization
JSON SerDe
The JSON SerDe deserializes JSON encoded change events and transforms it into a Java class. Internally this is achieved using Jackson Databind.
The consumer creates a serde instance using
final Serde<MyType> serde = DebeziumSerdes.payloadJson(MyType.class);
The consumer will then receive the logical Java type MyType
whose fields are initiated from the JSON message. This applies to both for keys and values. It is also possible to use plain Java types like Integer
, for example when the key consists of a single INT
field.
When the JSON converter is used by Kafka Connect then it generally provides two modes of operations - with or without schema. If the schema is used then the message looks like so:
{
"schema": {...},
"payload": {
"op": "u",
"source": {
...
},
"ts_ms" : "...",
"ts_us" : "...",
"ts_ns" : "...",
"before" : {
"field1" : "oldvalue1",
"field2" : "oldvalue2"
},
"after" : {
"field1" : "newvalue1",
"field2" : "newvalue2"
}
}
}
Whereas without schema, the structure look more like this:
{
"op": "u",
"source": {
...
},
"ts_ms" : "...",
"ts_us" : "...",
"ts_ns" : "...",
"before" : {
"field1" : "oldvalue1",
"field2" : "oldvalue2"
},
"after" : {
"field1" : "newvalue1",
"field2" : "newvalue2"
}
}
The deserializer behaviour is driven by the from.field
configuration option and follows these rules:
if a message contains a schema, then use
payload
onlyif the key is deserialized, then map key field(s) into the target class
if the value is deserialized and contains the Debezium event envelope then:
if
from.field
is not set, then deserialize the complete envelope into the target typeotherwise deserialize and map only content of the field configured into the target type, thus effectively flatting the message
if the value is deserialized and contains already a flattened message (i.e. when using the SMT for Event Flattening) then map the flattened record into the target logical type
Configuration options
Property | Default | Description |
| Empty if a message with full envelope should be deserialized, | |
| Determines when an unknown property is encountered whether it should be silently ignored or if a runtime exception should be thrown. |