Externalizable allows you to fully control serialization / deserialization. But this means that you are responsible for writing and reading each field,
When it becomes difficult, although it was once written out using default serialization, and you want to read it through Externalizable . (Or rather, this is not possible. If you try to read an object serialized using the default method using Externalizable , it will simply throw an exception.)
If you have absolutely no control over the exit, the only option is to save two versions of the class: use the default deserialization of the old version, and then convert it to the new one. The surface of this solution is that it keeps the "dirty" code in one place, separate from your nice and clean objects.
Again, if you do not want to do something really complicated, your best option is to save the old class as a "transport" bean and rename the class that your code really uses for something else.
source share