# Avro 反序列化失败：字段 'email' 没有默认值且在写入器模式中缺失

- **ID:** `data/avro-schema-field-missing-default`
- **领域:** data
- **类别:** schema_error
- **错误码:** `org.apache.avro.AvroTypeException: Field email type:STRING pos:12 not set and has no default value`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Avro 读取器模式中有一个没有默认值的字段，该字段在写入器模式中不存在，违反了前向兼容性。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Apache Avro 1.11.0 | active | — | — |
| Confluent Schema Registry 7.5.0 | active | — | — |

## 解决方案

1. ```
   Add a default value to the reader schema field: e.g., {"name": "email", "type": "string", "default": ""}
   ```
2. ```
   Use Avro's projection API to filter out unknown fields during deserialization: SpecificDatumReader<MyClass> reader = new SpecificDatumReader<>(writerSchema, readerSchema, new NoMatchFieldAction());
   ```

## 无效尝试

- **Adding the missing field to the writer schema** — This requires coordination with all data producers and may not be feasible for historical data. (70% 失败率)
- **Setting the field as 'optional' using union [null, string] in reader schema** — This changes the field type and may break downstream consumers expecting a non-nullable string. (60% 失败率)
