I am trying to user kryo to serialze a custom class which itself contains some custom objects, more specifically a HashMap of custom objects. I was wondering the proper way to handle something like this. Below is the class I am trying to serialize (Data), the classes which are nested, and my current kryo implementation. This is the right approach?
public class Data {
int id,
int name,
ItemList items;
}
public Class ItemList {
HashMap<String, Item> items;
}
public Class Item {
String itemId;
String itemName;
String itemDesc;
}
kryo.register(Data.class, new Serializer<Data>() {
public void write (Kryo kryo, Output output, Data object) {
output.writeInt(object.id);
output.writeInt(object.name);
kryo.writeClassAndObject(output, items);
}
public Tile read (Kryo kryo, Input input, Class<Data> type) {
Data data = new Data();
kryo.reference(data);
data.id = input.readInt();
data.name = input.readString();
data.items = kryo.readClassAndObject(input);
return data;
}
});