Reputation: 505
Just a simple question:
If I saved a java object on disk, but after that I added some more data member (String type), can new class read those old java object back with those new String member as null?
Upvotes: 0
Views: 269
Reputation: 17945
This is possible, but for that you need to manage compatibility actively. You need to ensure that the new class has the same serialVersionUID
value as the old class. This private static final long serialVersionUID
field can be auto-generated - or manually assigned. See http://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html
If you already have a serialVersionUID
, the new field will be null.
If you don't, you want to create one and use the same value as the auto-generated value of the old class. That's what the tool serialver
is for.
Upvotes: 1