I\'m trying to implement Writable class, but i have no idea on how to implement a writable class if in my class there is nested object, such as list, etc. Could any body help me
Serializing collections is quite simple.
@Override
public void readFields(DataInput in) throws IOException {
int size = in.readInt();
list= new ArrayList(size);
for(int i = 0; i < size; i++){
Field f = new Field();
f.readFields(in);
list.add(f);
}
}
@Override
public void write(DataOutput out) throws IOException {
out.writeInt(list.size());
for (Field l : list) {
l.write(out);
}
}
Field has to implement Writable
as well.