Ign*_*rre 7 json avro avro-tools
我正在尝试使用这种avro shcema
{
"namespace": "nothing",
"name": "myAvroSchema",
"type": "record",
"fields": [
{
"name": "checkInCustomerReference",
"type": "string"
},
{
"name": "customerContacts",
"type": "record",
"fields": [
{
"name": "customerEmail",
"type": "array",
"items": {
"type": "record",
"name": "customerEmail_element",
"fields": [
{
"name": "emailAddress",
"type": "string"
},
{
"name": "typeOfEmail",
"type": "string"
}
]
}
},
{
"name": "customerPhone",
"type": "array",
"items": {
"type": "record",
"name": "customerPhone_element",
"fields": [
{
"name": "fullContactNumber",
"type": "string"
},
{
"name": "ISDCode",
"type": "string"
}
]
}
},
{
"name": "DonotAskIndicator",
"type": "record",
"fields": [
{
"name": "donotAskDetails",
"type": "string"
}
]
}
]
},
{
"name": "somethingElseToCheck",
"type": "string"
}
]
}
Run Code Online (Sandbox Code Playgroud)
使用avro-tools生成和avro文件:
avro-tools fromjson --schema-file myAvroSchema.avsc myJson.json > myAvroData.avro
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误消息:
线程"main"中的异常org.apache.avro.SchemaParseException:"record"不是已定义的名称."customerContacts"字段的类型必须是已定义的名称或{"type":...}表达式.
谁能告诉我为什么记录没有被识别为一个定义的名称?
"customerContacts"字段的类型必须是已定义的名称或{"type":...}表达式
看起来不像您正确定义嵌套记录.我重现了你的架构,并提出了这个,尝试一下:
{
"type":"record",
"name":"myAvroSchema",
"namespace":"nothing",
"fields":[
{
"name":"checkInCustomerReference",
"type":"string"
},
{
"name":"customerContacts",
"type":{
"type":"record",
"name":"customerContacts",
"namespace":"nothing",
"fields":[
{
"name":"customerEmail",
"type":{
"type":"array",
"items":{
"type":"record",
"name":"customerEmail",
"namespace":"nothing",
"fields":[
{
"name":"emailAddress",
"type":"string"
},
{
"name":"typeOfEmail",
"type":"string"
}
]
}
}
},
{
"name":"customerPhone",
"type":{
"type":"array",
"items":{
"type":"record",
"name":"customerPhone",
"namespace":"nothing",
"fields":[
{
"name":"fullContactNumber",
"type":"string"
},
{
"name":"ISDCode",
"type":"string"
}
]
}
}
},
{
"name":"DonotAskIndicator",
"type":{
"type":"record",
"name":"donotAskIndicator",
"namespace":"nothing",
"fields":[
{
"name":"donotAskDetails",
"type":"string"
}
]
}
}
]
}
},
{
"name":"somethingElseToCheck",
"type":"string"
}
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4853 次 |
| 最近记录: |