【发布时间】:2021-09-09 09:43:37
【问题描述】:
我对 Avro 序列化完全陌生,我正试图弄清楚复杂类型是如何定义的。
我对 Avro 如何在 Java 中生成枚举感到困惑。
{
"type":"record",
"namespace":"com.example",
"name": "Customer",
"doc":"Avro Schema for our Customer",
"fields":[
{"name":"first_name","type":"string","doc":"First Name of Customer"},
{"name":"last_name","type":"string","doc":"Last Name of Customer"},
{"name":"automated_email","type":"boolean","doc":"true if the user wants marketing email", "default":true},
{
"name": "customer_type",
"type": ["null",
{
"name": "Customertype",
"type": "enum",
"symbols": ["OLD","NEW"]
}
]
}
]
}
注意customer_type 字段。如果我给出null,那么在我生成的源代码中,我会得到正确的Enum 类型,即:
private com.example.Customertype customer_type;
但是当我删除 null 值并以下列方式定义 customer_type 时:
{
"name": "customer_type",
"type": [
{
"name": "Customertype",
"type": "enum",
"symbols": ["OLD","NEW"]
}
]
}
声明更改为:
private Object customer_type;
那个“null”字符串是什么意思?为什么它很重要?
我已尝试查看 AVRO 规范,但没有任何东西给我一个明确的答案为什么会这样工作。
我正在使用 AVRO Maven 插件。
任何 AVRO 初学者资源也将不胜感激。
谢谢。
【问题讨论】:
标签: avro avro-tools