Avro 模式可选数组为 null
Avro schema optional array as null
当数组属性有null
时,我无法序列化数据。我正在使用 KafkaAvroSerializer.class 作为 value.serializer
属性
Testing.avsc:
{ "namespace": "com.kafka.schema", "name": "Testing", "type": "record", "fields": [{ "name": "names", "type" : { "type": "array", "items": [ "null", "string" ], "default": [] } }] }
错误:
原因:org.apache.kafka.common.errors.SerializationException: Error serializing Avro message
原因:java.lang.NullPointerException: null of array of com.kafka.schema.Testing
如果数组本身可以为 null,我会写 null
作为可接受的 type
,而不是数组中的可接受值。
{
"namespace":"com.kafka.schema",
"name":"Testing",
"type":"record",
"fields":[
{
"name":"names",
"type":[
{
"type":"array",
"items":[
"null",
"string"
],
"default":[
]
},
"null"
]
}
]
}
当数组属性有null
时,我无法序列化数据。我正在使用 KafkaAvroSerializer.class 作为 value.serializer
属性
Testing.avsc:
{ "namespace": "com.kafka.schema", "name": "Testing", "type": "record", "fields": [{ "name": "names", "type" : { "type": "array", "items": [ "null", "string" ], "default": [] } }] }
错误:
原因:org.apache.kafka.common.errors.SerializationException: Error serializing Avro message
原因:java.lang.NullPointerException: null of array of com.kafka.schema.Testing
如果数组本身可以为 null,我会写 null
作为可接受的 type
,而不是数组中的可接受值。
{
"namespace":"com.kafka.schema",
"name":"Testing",
"type":"record",
"fields":[
{
"name":"names",
"type":[
{
"type":"array",
"items":[
"null",
"string"
],
"default":[
]
},
"null"
]
}
]
}