0

我有 Avro Schema:客户记录导入 CustomerAddress 子集。

[
  {
      "type": "record",
      "namespace": "com.example",
      "name": "CustomerAddress",
      "fields": [
        { "name": "address", "type": "string" },
        { "name": "city", "type": "string" },
        { "name": "postcode", "type": ["string", "int"] },
        { "name": "type","type": {"type": "enum","name": "type","symbols": ["POBOX","RESIDENTIAL","ENTERPRISE"]}}
      ]
  },
  {
     "type": "record",
     "namespace": "com.example",
     "name": "Customer",
     "fields": [
       { "name": "first_name", "type": "string" },
       { "name": "middle_name", "type": ["null", "string"], "default": null },       
       { "name": "last_name", "type": "string" },
       { "name": "age", "type": "int" },
       { "name": "height", "type": "float" },
       { "name": "weight", "type": "float" },
       { "name": "automated_email", "type": "boolean", "default": true },
       { "name": "customer_emails", "type": {"type": "array","items": "string"},"default": []},
       { "name": "customer_address", "type": "com.example.CustomerAddress" }
     ]
  }
]

我有 JSON 有效负载:

{
    "Customer" : {
         "first_name": "John",
         "middle_name": null,
         "last_name": "Smith",
         "age": 25,
         "height": 177.6,
         "weight": 120.6,
         "automated_email": true,
         "customer_emails": ["ning.chang@td.com", "test@td.com"],
         "customer_address":
         {
             "address": "21 2nd Street",
             "city": "New York",
             "postcode": "10021",
             "type": "RESIDENTIAL"
         }
    }
}

当我运行命令时:java -jar avro-tools-1.8.2.jar fromjson --schema-file customer.avsc customer.json

得到以下异常:

Exception in thread "main" org.apache.avro.AvroTypeException: Unknown union branch Customer
4

1 回答 1

0

在您的 JSON 数据中,您使用密钥Customer,但您必须使用完全限定名称。所以应该是com.example.Customer

于 2021-08-27T13:33:32.280 回答