C
C#10mo ago
br4kejet

Version based serialisation

Is there a good way to implement version-based serialisation? E.g. if ObjectA has some serialisable data in version 1.0, but in v1.1 some things are removed and new things are added, how do you maintain backwards compatibility with the old serialised data?
2 Replies
br4kejet
br4kejetOP10mo ago
Obviously new data versions won't work on old versions of the app, but old data versions on the new versions of the app should work (maybe by using default values) I like the idea of using new types of objects but if I do that for every new change then it's gonna be really messy ObjectAv1, ObjectAv2, ObjectAv3, etc. I was thinking of creating a dictionary that maps a Type to a map that maps a version number to a serialiser and deserialiser, but I get the feeling it's a dumb idea If a version isn't present in that 2nd map then it would find the nearest previous version
lycian
lycian10mo ago
Not sure it's the best design, but this sounds similar to back compat things that APIs deal with. A lot of times you'll see interfaces like IObject, IObject2, IObject3, etc. You can at least then have a definition of what data is available through the interface but have one single underlying object definition that implements all of the interfaces
Want results from more Discord servers?
Add your server