JSON到Avro转换例外-预期的开始联盟。得到了VALUE_STRING

时间:2020-02-04 08:28:37

标签: java json apache-kafka schema avro

我有以下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类型的数组)

1 个答案:

答案 0 :(得分:1)

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

尝试以下方法:

{"redeliveredDataEventIndices":[]}