首页 > 解决方案 > JSON to Avro conversion exception - Expected start-union. Got VALUE_STRING

问题描述

I have the following avsc (Avro schema) :

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

When i try to convert json to avro with this Schema i get the following error :

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

My input data :

{"redeliveredDataEventIndices":"[]"}

I know this is a duplicate of How to fix Expected start-union. Got VALUE_NUMBER_INT when converting JSON to Avro on the command line? but how to give input for the type array (redeliveredDataEventIndices is array of type int in this case)

标签: javajsonapache-kafkaschemaavro

解决方案


您的输入数据将数组括在引号中,因此将其视为字符串。

试试这个:

{"redeliveredDataEventIndices":[]}

推荐阅读