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

  1. 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:

  1. {
  2. "schema": {...},
  3. "payload": {
  4. "op": "u",
  5. "source": {
  6. ...
  7. },
  8. "ts_ms" : "...",
  9. "ts_us" : "...",
  10. "ts_ns" : "...",
  11. "before" : {
  12. "field1" : "oldvalue1",
  13. "field2" : "oldvalue2"
  14. },
  15. "after" : {
  16. "field1" : "newvalue1",
  17. "field2" : "newvalue2"
  18. }
  19. }
  20. }

Whereas without schema, the structure look more like this:

  1. {
  2. "op": "u",
  3. "source": {
  4. ...
  5. },
  6. "ts_ms" : "...",
  7. "ts_us" : "...",
  8. "ts_ns" : "...",
  9. "before" : {
  10. "field1" : "oldvalue1",
  11. "field2" : "oldvalue2"
  12. },
  13. "after" : {
  14. "field1" : "newvalue1",
  15. "field2" : "newvalue2"
  16. }
  17. }

The deserializer behaviour is driven by the from.field configuration option and follows these rules:

  • if a message contains a schema, then use payload only

  • if 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 type

    • otherwise 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

N/A

Empty if a message with full envelope should be deserialized, before/after if only data values before or after the change are required.

false

Determines when an unknown property is encountered whether it should be silently ignored or if a runtime exception should be thrown.