{
  "id": "data/avro-union-null-ordering",
  "signature": "Avro deserialization fails when union field has null as first element instead of last",
  "signature_zh": "当联合字段将null作为第一个元素而非最后一个时，Avro反序列化失败",
  "regex": "Avro.*union.*null.*order|union.*null.*first|Avro.*deserialization.*union",
  "domain": "data",
  "category": "serialization_error",
  "subcategory": null,
  "root_cause": "Some Avro libraries expect null to be the first element in a union type (e.g., ['null', 'string']), while others expect it last, causing schema compatibility issues.",
  "root_cause_type": "generic",
  "root_cause_zh": "某些Avro库期望null是联合类型中的第一个元素（例如['null', 'string']），而其他库期望它在最后，导致架构兼容性问题。",
  "versions": [
    {
      "version": "Apache Avro 1.11.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Confluent Schema Registry 7.4.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Kafka 3.5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Setting compatibility to NONE in schema registry",
      "why_fails": "Changing schema registry compatibility type does not fix the union ordering issue.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Modifying the data to include null values in a different order",
      "why_fails": "The null position is determined by the schema, not the data payload.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure all Avro schemas use the same union ordering convention: always put null first: {\"type\": [\"null\", \"string\"]}",
      "success_rate": 0.95,
      "how": "Ensure all Avro schemas use the same union ordering convention: always put null first: {\"type\": [\"null\", \"string\"]}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a custom deserializer that reorders union types: GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(writerSchema, readerSchema) { @Override protected Object read(Object old, Decoder in) throws IOException { return super.read(old, in); } };",
      "success_rate": 0.7,
      "how": "Use a custom deserializer that reorders union types: GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(writerSchema, readerSchema) { @Override protected Object read(Object old, Decoder in) throws IOException { return super.read(old, in); } };",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure all Avro schemas use the same union ordering convention: always put null first: {\"type\": [\"null\", \"string\"]}",
    "Use a custom deserializer that reorders union types: GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(writerSchema, readerSchema) { @Override protected Object read(Object old, Decoder in) throws IOException { return super.read(old, in); } };"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://avro.apache.org/docs/1.11.0/spec.html#Unions",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-11-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}