I’m thinking this is impossible via the direct approach, but I’ll ask.
Say I have a serializable class Stringy with string A and string B that I’ve written off to the hard disk. In a later version string C gets added to the class Stringy. Now if I try to read the old files they will expect a string C in any Stringy instance and will throw errors.
Is there any common or best practice way to deal with this?
To expand, I wrap all my files in classes. PlayerDataHolder has playerLevel, playHealth, etc. I can just write it off to disk, pull it back off disk, and all the variables are there and good. If I want to add playerDexterity later on though all the old saved files won’t load with the modern loader. Can I:
- Create a new class PlayerDataHolder2 with playerDexterity in it, and attempt to input the file as a PlayerDataHolder if it failed to load as a PlayerDataHolder2.
- Make a generic DataHolder empty class and make all of my saved files inherent of it, instead detecting the object type after I’ve read it off the disk.
- Some way to detect file type (not via extension/name) prior to deserialization?
Number 2 sounds like cheating… I’m going to try that when I get home. Has anyone managed something like this before?