我是Avro的新手,正在嘗試編寫一些代碼來序列化一些嵌套的對象。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。
所以當序列化一個包裹時,我該如何'放'每個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(????
任何想法?
我有一種感覺,我的方法是錯誤的,但在動態模式生成或嵌套地圖的文檔中找不到任何示例。