JSON 到 Avro 的转换异常 - 预期的开始联合。得到 VALUE_STRING

JSON to Avro conversion exception - Expected start-union. Got VALUE_STRING

我有以下 avsc(Avro 模式):

{
  "type": "record",
  "name": "DataEventId",
  "fields": [
    {
      "name": "redeliveredDataEventIndices",
      "type": { "type": "array", "items": "int" },
      "doc" : "Data event indices",
      "default": []
    },
  ],
  "namespace": "com.xxx.xxx.xxx"
}

当我尝试使用此架构将 json 转换为 avro 时,出现以下错误:

org.apache.avro.AvroTypeException: Expected start-union. Got VALUE_STRING

我的输入数据:

{"redeliveredDataEventIndices":"[]"}

我知道这是 How to fix Expected start-union. Got VALUE_NUMBER_INT when converting JSON to Avro on the command line? 的副本,但是如何为类型数组提供输入(在这种情况下,redeliveredDataEventIndices 是 int 类型的数组)

您的输入数据包含用引号引起来的数组,因此将其视为字符串。

试试这个:

{"redeliveredDataEventIndices":[]}