Results 1 to 3 of 3

Thread: Serialization - backward compatibility

  1. #1

    Thread Starter
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Serialization - backward compatibility

    I'm using serialization to save the data from my application to disk. It works fine but I'm forseeing a problem.

    In future versions of the application there will be changes to the structure of the classes that are serialized. This means that future versions of the app will be unable to read old project files.

    Has anybody had any experience of getting around this problem? Can you let me know any techniques? The only one I can think of so far is to serialize in XML then manipulate the text to conform to the new class structure. Sounds a bit messy...
    This world is not my home. I'm just passing through.

  2. #2
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    Hmmm, all that I can think of, off the top of my head, is to keep an old version of the classes that you are serializing. That way you can deserialize to the old version of the classes, read the values into the new version of the classes, and then serialize again. You could offer the functionality as an upgrade wizard or something. Thoughts?
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I would just forget about serializing the objects and storing the information in an XML file yourself. I am assuming you will extend the objects that you are serializing to include more properties..., if this is correct, then you just will extend your XML file to include more elements. When you read in the file, you can fill the objects properties by what is in the xml file.

    So, lets say you have object A with 5 properties. You will have an XML file with 5 elements.

    Now, later, you extend object A to have 10 properties, but you want to be able to be backwards compatible. So when you read in the XML file, you fill the 5 properties you know will be there, then you look to see if the others are there. If they are, then it is a newer version of the XML file, and go ahead and read them in. If they are not, then you just supply default values to the 5 new object properties.

    Hope that helps. I know serialization is quick and dirty, but probably not the most functional for this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width