Introduction
I have the following class:
public class Foo extends ArrayList<ElementsClass> implements Externalizable {
Field field1 = new Field();
Field field2 = new Field();
...
}
I implement the methods writeExternal
and readExternal
like this:
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(field1);
out.writeObject(field2);
}
public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException {
field1 = (Field) in.readObject();
field2 = (Field) in.readObject();
}
Observation
One of the fields is not Serializable
that is why I implement Externalizable
. I want to externalize only those things that I am able to.
Problem
Although I know that the ArrayList<ElementsClass>
is serializable if ElementsClass
is serializable, I don't know how to externalize the class Foo
itself.