'Is there a way to make Google Cloud Pub/Sub Schema fields optional?

The title says it all, really. I'm struggling to figure out how to make a Google Cloud Pub/Sub schema that has optional fields. Or would having optional fields in an AVRO schema basically directly contradict the whole point of having a schema?

The structure I tried is this, with no success:

{
  "type": "record",
  "name": "Avro",
  "fields": [
    {
      "name": "TestStringField",
      "type": ["null", "string"],
      "default": ""
    },
    {
      "name": "TestIntField",
      "type": ["null", "int"],
      "default": 0
    }
  ]
}


Sources

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

Source: Stack Overflow

Solution Source