Your problem is in the serialization:
oos.writeObject(listaPessoas.add(p1));
this writes the return value of List.add()
which is a boolean (true if the collection is changed by the operation) which is then boxed in a Boolean
.
When you then deserialize:
listaPessoas = (ArrayList<Pessoa>) ois.readObject();
a Boolean is found in the stream, but you try to cast it to List, generating the class cast exception.
Just keep the serialization of the list in a single statements like:
listaPessoas.add(value);
[...] // other operation on the list
oos.writeObject(listaPessoas);