【问题标题】:Avro schema : List of generic typesAvro 架构:泛型类型列表
【发布时间】:2018-02-17 10:22:34
【问题描述】:

这是我在 Avro 中尝试为其编写架构的 Java 等价物:

abstract class Vehicle {}
class Bike extends Vehicle {}
class Car extends Vehicle {}
class Bus extends Vehicle {}

现在,我想要一个带有 List 车辆的文件,例如:

List<Vehicle> vehicles = ;

列表中的元素可以是 Bike、Car 或 Bus。现在,将其与 Avro 模式进行比较,我可以看到 Array type,所以我可能不得不写这样的东西(抱歉 Avro 部分的绝望,我以前没有使用过它):

{
  "name" : "vehicles",
  "type" : "array",
  "items" : {
    "name" : "???"
  }
}

这是我所能做到的,有没有办法指定这些项目可以是自行车、汽车或公共汽车之一?

【问题讨论】:

    标签: java schema avro


    【解决方案1】:

    您是否尝试过在项目中使用联合作为

    "items":["Bike","Car","Bus"]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 1970-01-01
      • 2015-04-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多