【发布时间】:2017-03-07 16:02:23
【问题描述】:
我是 Avro 新手,正在尝试编写一些代码来序列化一些嵌套对象。
对象的结构如下所示:
class Parcel {
String recipe;
Map<Integer, PluginDump> dumps;
}
class PluginDump {
byte[] state;
Map<String, Param> params;
}
class Param {
Type type; //can be e.g. StringType, BooleanType, etc
Object value;
}
所以我不能使用静态 avro 架构 - 每个 PluginDump 都会有不同的架构,具体取决于其中的类型。
我已经编写了一些代码,可以基于单个 PluginDump 生成 Schema。
那么在序列化 Parcel 时,我如何“放置”每个 PluginDump 条目?
这是我的代码:
Schema parcelSchema = AvroHelper.getSchema(p);
GenericRecord parcelRecord = new GenericData.Record(parcelSchema);
parcelRecord.put("recipe", p.getRecipe().toJson());
for (Map.Entry<Integer, PluginDump> entry : p.getDumps().entrySet()) {
PluginDump dump = entry.getValue();
Integer uid = entry.getKey();
Schema dumpSchema = AvroHelper.getSchema(dump);//will be different for each PluginDump
parcelRecord.put(????
有什么想法吗?
我感觉我的方法是错误的,但我在动态模式生成或嵌套映射的文档中找不到任何示例。
【问题讨论】:
标签: avro