How to fix Expected start-union. Got VALUE_NUMBER_INT when converting JSON to Avro on the command line?

后端 未结 4 2080
感动是毒
感动是毒 2020-11-27 17:01

I\'m trying to validate a JSON file using an Avro schema and write the corresponding Avro file. First, I\'ve defined the following Avro schema named user.avsc:<

4条回答
  •  伪装坚强ぢ
    2020-11-27 17:43

    According to the explanation by Doug Cutting,

    Avro's JSON encoding requires that non-null union values be tagged with their intended type. This is because unions like ["bytes","string"] and ["int","long"] are ambiguous in JSON, the first are both encoded as JSON strings, while the second are both encoded as JSON numbers.

    http://avro.apache.org/docs/current/spec.html#json_encoding

    Thus your record must be encoded as:

    {"name": "Alyssa", "favorite_number": {"int": 7}, "favorite_color": null}
    

提交回复
热议问题