Apache Avro 中的枚举序列化/反序列化失败

时间:2021-04-22 12:19:40

标签: java enums avro jackson-dataformat-avro

json 中的示例枚举值:

"color": {
    "com.abc.colortype": "green"
}

avsc 文件中的 Avro 架构:

{
    "name" : "color",
    "type" : [ "null", {
      "type" : "enum",
      "name" : "colortype",
      "doc" : "Either red , blue or green",
      "symbols" : [ "red", "blue", "green" ],
      "hierarchy" : "/badgecolor/"
    } ],
    "doc" : "Either red , blue or green",
    "default" : null
  }

json 反序列化为 org.apache.avro.generic.GenericRecord 就好了。 但是 GenericRecord 序列化是这样写的:

"color": "green"

apache-avro 无法理解这个枚举表示。 Next 将 JSON 反序列化为 GenericRecord 失败。它报告模式兼容性错误。我们如何调整序列化以使用带有命名空间的格式?

0 个答案:

没有答案