我需要在Schema中混合使用"record“类型和null类型。
"name":"specShape",
"type":{
"type":"record",
"name":"noSpecShape",
"fields":[
{
"name":"bpSsc",
"type":"null",
"default":null,
"doc":"SampleValue: null"
},...例如,对于某些数据,specShape可能为null。
因此,如果我将type设置为
"name":"specShape",
"type":{
**"type":["record", "null"],**
"name":"noSpecShape",
"fields":[
{
"name":"bpSsc",
"type":"null",
"default":null,
"doc":"SampleValue: null"
},...上面写着
No type: {"type":["record","null"]...但如果我将呼叫器类型设置为
"name":"specShape",
**"type":[{
"type":"record",
"name":"noSpecShape",
"fields":[
{
"name":"bpSsc",
"type":"null",
"default":null,
"doc":"SampleValue: null"
}, "null"]**,...上面写着
Not in union [{"type":"record"如何将这两种类型结合起来?
发布于 2016-03-31 09:36:16
您的想法是正确的,您只需要将"null"包含在更高级别的"type"数组中,而不是包含在"fields"数组中(如第三个示例所示)。这是可空记录的架构:
[
"null",
{
"type": "record",
"name": "NoSpecShape",
"fields": [
{
"type": "null",
"name": "bpSsc",
"default": null
}
]
}
]您还可以将其嵌套在需要类型声明的任何位置,例如,在另一条记录中:
{
"type": "record",
"name": "SpecShape",
"fields": [
{
"type": [
"null",
{
"type": "record",
"name": "NoSpecShape",
"fields": [
{
"type": "null",
"name": "bpSsc",
"default": null
}
]
}
],
"name": "shape"
}
]
}最后一个模式的JSON编码实例将如下所示:
{"shape": null}{"shape": {"NoSpecShape": {"bpSsc": null}}}https://stackoverflow.com/questions/36321616
复制相似问题