'JSON example of nullable complex type in AVRO

I created a avro schema to validate the messages that I publish on a kafka topic. These messages consist of complex types that contain other complex types. Not all fields are required, so I figured out I need to use union types in avro for that.

So basically at some point my avro schema looks like this:

"type" : "record",
"name" : "RecordA",
"fields" : [ {
  "name" : "fieldX",
  "type" : [ "null", {
    "type" : "record",
    "name" : "RecordB",
    "fields" : [ {
      "name" : "gemeente",
      "type" : "string"
    }, {
      "name" : "nummer",
      "type" : "string"
    }, {
      "name" : "postcode",
      "type" : "string"
    }, {
      "name" : "straat",
      "type" : "string"
    } ]
  } ]

Can someone give me an example of how a json message that adheres to this schema would look like? All the examples I found refer to simple union types that consist of primitive values.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source