I serialize a ArrayList<packageA.Changelog> list
to a file and transmitted the file to another system in another machine.
And since it's a different system that received the file, I don't have the same packageA.Changelog
class, instead is a packageB.Changelog
which has exactly same structure but in different package.
And when I use
ArrayList<packageB.Changelog> changelogs = (ArrayList<packageB.Changelog>)ois.readObject();
to read out from the file I got a ClassCastException
.
How to avoid this exception? Do I need to create the same package structure in the other system only for receiving the list?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…