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 8301277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:52:47+00:00 2026-06-08T16:52:47+00:00

I have the following classes: [Serializable] public class ExtendedAddressData { public String AddressLine1 {

  • 0

I have the following classes:

    [Serializable]
    public class ExtendedAddressData
    {
        public String AddressLine1 { get; set; }
        public String AddressLine2 { get; set; }
        public String Country { get; set; }
        public String City { get; set; }
        public String Firstname { get; set; }
        public String Surname { get; set; }
        public String FakeField { get; set; }
    }

    [Serializable]
    public class AddressData
    {
        public String AddressLine1 { get; set; }
        public String AddressLine2 { get; set; }
        public String Country { get; set; }
        public String City { get; set; }
        public String ZipCode { get; set; }
        public String Firstname { get; set; }
        public String Surname { get; set; }
    }

Im trying to make sure that old AddressData is still deserializable in the future despite being serialized with a slightly different class.

Basically the fields that are empty (none existing) should be blanked out and those that were removed should be forgotten.

I am serializing from Object to Byte[] (and back). Not to XML or JSON

    private static byte[] ObjectToByteArray(object _Object)
    {
        try
        {
            var memoryStream = new MemoryStream();
            new BinaryFormatter().Serialize(memoryStream, _Object);
            return memoryStream.ToArray();
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught in process: {0}", e);
        }
        return null;
    }

    private static object ByteArrayToObject(byte[] aBytes)
    {
        try
        {
            var memoryStream = new MemoryStream(aBytes);
            var serializedObject = new BinaryFormatter().Deserialize(memoryStream);
            return serializedObject;

        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught in process: {0}", e);
        }
        return null;
    }

here is a simplified UnitTest that probably explains what im trying better than i can

    public void LegacySerializationSupportTest()
    {
        var realData = new AddressData()
        {
            AddressLine1 = "AddressLine1",
            AddressLine2 = "AddressLine2",
            City = "City",
            Country = "Country",
            Firstname = "Firstname",
            Surname = "Surname",
            ZipCode = "ZipCode"
        };
        var bytearray = AddressRepository_Accessor.ObjectToByteArray(realData);

        AddressData realObject = (AddressData) AddressRepository_Accessor.ByteArrayToObject(bytearray);
        ExtendedAddressData fakeObject = (ExtendedAddressData) AddressRepository_Accessor.ByteArrayToObject(bytearray);
        Assert.AreEqual(realObject.AddressLine1,fakeObject.AddressLine1);
    }

Is there any way i can do this and still use bytearray instead of JSON or XML?

  • 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-06-08T16:52:48+00:00Added an answer on June 8, 2026 at 4:52 pm

    I agree with James. It isn’t just an architectual thing (DRY principle) if the old class and the new class are both inherit from the same parent you can get the job done. Make a serializer on the parent class that will output the “null” values for the missing values from the one class and simply doesn’t even contain the fields from the other one you want to exclude. Then call the serializer on the parent class rather than the derived class and everything will end up coming out looking the same.

    On the child classes you’ll still have to figure out what you want to do with values that aren’t contained in the new serialization format though (ie will the rest of your code be happy getting a class with that field empty?).

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

Sidebar

Related Questions

I have following classes public class Person { public string FirstName { get; set;
I have the following classes: public class Note { public string Text { get;
I have the following classes [XmlRoot] public class AList { public List<B> ListOfBs {get;
I have the following classes [Serializable()] public class ColumnList { public ColumnList() { ListOfColumns
I have the following classes created: [Serializable] public class AppContext : IXmlSerializable { public
I have the following classes [Serializable] [XmlRoot(fileset)] public class FileSet { [XmlArray()] [XmlArrayItem(ElementName=file)] public
I have following classes in my project. [Serializable] public class BaseEntityCollection<T> : List<T> where
Suppose, I have following classes: public class DisposableObj : IDisposable { public ChildObj CreateObj();
I have the following classes defined to do validation: public class DefValidator : IValidate<IDef>
I have the following classes in my Model: public abstract class Entity : IEntity

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.