Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 601439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:42:55+00:00 2026-05-13T16:42:55+00:00

It sounds strange but this is exactly what I want because I am using

  • 0

It sounds strange but this is exactly what I want because I am using a data structure named “Project” which gets serialized to a save file. I would like to be able to de-serialize an older version of a save file with deprecated fields in tact, but then re-serialize it using only the currently used fields. The problem is that I want to get rid of those deprecated fields when re-serializing the structure in order to minimize file size. Is it possible to mark a field as “de-serializable only”?

Edit:

Thanks for the ideas! I decided to build mostly off of NickLarsen’s suggestions and create an old version of the project structure with all depreciated fields in a separate namespace. The difference is that I decided to perform the upgrade upon deserialization. This is great because I can do it all in one line (hopefully you can get the gist what I’m doing here):

Project myProject = new Project((Depreciated.Project)myFormatter.Deserialize(myStream));

The constructor simply returns a new instance of the fresh minimal data structure based on the old bloated one.

Second Edit:

I decided to follow the advice of bebop instead and create new classes for each project version with the oldest version including all depreciated and new fields. Then the constructor of each project upgrades to the next version getting rid of depreciated fields along the way. Here is an illustrative example of converting from version 1.0.0 -> 1.0.5 -> current.

Project myProject = new Project(new Project105((Project100)myFormatter.Deserialize(myStream)));

One key to this is to forced the deserialized file as well as any fields into the older versions of the classes by using a SerializationBinder.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:42:56+00:00Added an answer on May 13, 2026 at 4:42 pm

    could you not create a new version of your data structure class each time the structure changes, and have the constructor for the new class take an instance of the previous class, and populate itself from there. To load the newest class you try and create the earliest class from the serialised file until one succeeds, and then pass that into the constructor of the next class in the chain repeatedly until you get the latest version of the data structure then you can save that.

    Having a new class for each change in format would avoid having to change any existing code when the data structure changed, and your app could be ignorant of the fact that the save file was some older version. It would allow you to load from any previous version, not just the last one.

    This sort of thing implemented by a chain of responsibility can make it easy to slot in a new format with minimal changes to your existing code.

    Whilst not a textbook chain of responsibility you could implement with something like this:

    (NOTE: untested code)

    public interface IProductFactory<T> where T : class
    {
        T CreateProduct(string filename);
        T DeserializeInstance(string filename);
    }
    
    public abstract  class ProductFactoryBase<T> :  IProductFactory<T> where T : class
    {
        public abstract T CreateProduct(string filename);
    
        public T DeserializeInstance(string filename)
        {
            var myFormatter = new BinaryFormatter();
            using (FileStream stream = File.Open(filename, FileMode.Open))
            {
                return myFormatter.Deserialize(stream) as T;
            }
    
        }
    }
    
    public class ProductV1Factory : ProductFactoryBase<ProductV1>
    {
        public override ProductV1 CreateProduct(string filename)
        {
            return DeserializeInstance(filename);
        }
    }
    
    public class ProductV2Factory : ProductFactoryBase<ProductV2>
    {
        ProductV1Factory successor = new ProductV1Factory();
        public override ProductV2 CreateProduct(string filename)
        {
            var product = DeserializeInstance(filename);
            if (product==null)
            {
                product = new ProductV2(successor.CreateProduct(filename));
            }
            return product;
        }
    
    }
    
    public class ProductV2
    {
        public ProductV2(ProductV1 product)
        {
            //construct from V1 information
        }
    }
    
    
    public class ProductV1  
    {
    }
    

    this has the advantage that when you want to add ProductV3 you only need to change the class you are using in your app to be a ProductV3 type, which you need to do anyway, then you change your loading code so that it uses a ProductV3Factory, which is basically the same as a ProductV2Factory, but it uses a ProductV2Factory as the successor. You don’t need to change any existing classes. you could probably refactor this a bit to get the commanality of CreateProduct into a base class, but it gets the idea across.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question may sounds strange but I want to make this question clear. Some people
This sounds pretty strange, but there is ocurring in a databases of a bunch
I know this sounds strange, mixing CDI (Weld) and Spring for the controller. But
I know it sounds a little bit strange, but I want a javascript function
I know this may sound strange, but I want to retrieve the system default
I know this sounds strange, but on my development box I can't go back
Hey everyone quick question, I know this sounds strange to do in javascript but
I've got a question that might sound strange. We are using node.js, but the
Sounds like a stupid question, doesn't it? But the page on the Jettison project
This sounds like a really simple question, but I am new to PHP. If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.