【发布时间】:2019-07-26 06:07:36
【问题描述】:
我有这个 json 字段,该字段仅在极少数情况下是可选的。我总是使用 Avro 模式验证我的 json,因为我按要求放置它,所以它失败了。
示例 json 正常情况:
{"records" :[ {
"unit": "< 50'000",
"val1": "0.1000",
"val2": "0.0000"
},{
"unit": "< 150'000",
"val1": "0.2000",
"val2": "0.1000"
}]}
示例 json 罕见情况(val2 是可选的)
{"records" :[ {
"unit": "< 50'000",
"val1": "0.1000"
},{
"unit": "< 150'000",
"val1": "0.2000"
}]
}
我试图将我的架构更改为:
{
"name": "KafkaFCFD",
"type": "record",
"namespace": "com.myCompany.test",
"fields": [
{
"name": "records",
"type": {
"type": "array",
"items": {
"name": "records_record",
"type": "record",
"fields": [
{
"name": "unit",
"type": "string"
},
{
"name": "val1",
"type": "string"
},
{
"name": "val2",
"type": ["string","null"],
"default": "0.0"
}
]
}
}
}
]
}
但这只会给我这个例外:
Expected start-union. Got END_OBJECT
关于如何解决这个问题的任何想法?
【问题讨论】: