1

我正在尝试为以下 json 创建 avro 架构

  {
  "id": "TEST",
  "status": "status",
  "timestamp": "2019-01-01T00:00:22-03:00",
  "comment":  "add comments or replace it with adSummary data",
  "error": { 
    "code": "ER1212132",
    "msg": "error message"
  }
}

错误对象是可选的,它可能是“错误”:{} 下面是没有默认值的 avro 架构

{
  "type" : "record",
  "name" : "Order",
  "fields" : [ {
    "name" : "id",
    "type" : "string"
  }, {
    "name" : "status",
    "type" : "string"
  }, {
    "name" : "timestamp",
    "type" : "string"
  }, {
    "name" : "comment",
    "type" :  ["null","string"],
    "default": null
  }, {
    "name" : "error",
    "type" : {
      "type" : "record",
      "name" : "error",
      "fields" : [ {
        "name" : "code",
        "type" : "string"
      }, {
        "name" : "msg",
        "type" : "string"
      } ]
    }
  } ]
}

如何为 json 中的错误字段添加默认值 {}。

4

1 回答 1

0

{
  "type" : "record",
  "name" : "Order",
  "fields" : [ {
    "name" : "id",
    "type" : "string"
  }, {
    "name" : "status",
    "type" : "string"
  }, {
    "name" : "timestamp",
    "type" : "string"
  }, {
    "name" : "comment",
    "type" :  ["null","string"],
    "default": null
  }, {
    "name" : "error",
    "type" : [{"type": "record", "fields":[{"name": "code", "type":"string"}, {"name": "msg", "type":"string"}]}, {"type": "record", "fields":[]}]
  
  } ]
}

于 2020-07-07T06:30:09.527 回答