A few months back I serialized a java.io.Serializable object into a file. Now I need to read the contents, but since then the serialVersionUID has changed, and now I\'m get
I recently found myself in a similar situation--I had some serialized objects that I had to read, the serialVersionUID
of those objects was different than the newest version and, in my case, there were a couple of different serialVersionUID
s stored in the file for the same class (stored at different times, obviously). So I didn't have the luxury of modifying the class and setting its serialVersionUID
; I actually had to go in and modify the stored data.
What I figured out (by reading the java.io source code) is that an object gets serialized by first storing the class name (using writeUTF()
) and then immediately after using writeLong()
to save the serialVersionUID
.
My solution was to catch the exception then go back, look for the class name, and immediately after the class name replace the old serialVersionUID
with the new.