我需要在. avsc
文件中定义一个模式,该模式将使用maven插件编译,以创建类。
该类必须是一棵树,其中root是不同类型的,并且所有节点都是另一种类型。
例如:
(Root) -> (Node A) -> (Node C) -> (Node F)
- -> (Node D)
- -> (Node E)
- -> (Node B) -> (Node F)
要遵循此结构,类需要遵循:
class Node {
String id;
String name;
ArrayList<Node> children;
}
class Root {
ArrayList<Node> children;
}
我知道我可以简单地扩展SpecficRecordBase
使我的类遵循使用相同插件生成的其他记录
类的结构,以及avro模式;但是有没有办法使用avro模式创建这样的结构?
这应该起作用:
{
"namespace": "com.tree.yournamespace",
"type": "record",
"name": "TreeRoot",
"fields": [
{
"name": "nodes", "type": {
"type": "array",
"items": {
"name": "Node",
"type": "record",
"fields": [
{"name": "children", "type": {
"type": "array",
"items": "Node"
}
}
]
}
}
}
]
}