0

I have a base class in my SDK (Geometry) that serializes its members. Some members are just simple attributes & Elements like strings, and others are arrays of user defined classes. Now, I need to accommodate a change in my workflows which causes the base class to be child of a parent class which means the XML hierarchy will change as well. And, also I want to rename some of the attributes/elements.

But, what about the XMLs that were serialized with previous SDK code (class hierarchy). How do I de-serialize those XMLs into the new SDK?

<Geometry Type"Test" IsAssessed="False">
    <Name>Sample Geometry</Name>
    <LengthA>69</LengthA>
    <LengthB>87</LengthB>
    <LengthC>50</LengthC>
        <Points>
            <Point X="1537308.5" Y="16030594.72" Z="1000">
                <IsTracked>false</IsTracked>
            </Point>
            <Point X="1537308.5" Y="16030594.72" Z="900">
                <IsTracked>false</IsTracked>
            </Point>
            <Point X="1536601.21" Y="16028954.3" Z="-5670.6">
                <IsTracked>false</IsTracked>
            </Point>
        </Points>
</Geometry>

So, Lets say after change is Made, a class is introduced whose name is Calculator and it has a collection of Geometry. But I want to rename Geometry as well as rename some of its elements/Attributes. And add/delete attributes too.

How do I go about it so that my previous XML's de-serialize successfully.

WAQ
  • 2,556
  • 6
  • 45
  • 86

1 Answers1

0

Have a look at Version Tolerant Serialization.

This allows you to add tags (OptionalField, OnDeserializing, etc) to account for changes in the XML structure.

Alternatively, if it's a once off you could de-serialize into the old version and then implement conversion code to update to the new version. This could get very difficult to maintain if it's something that's regularly happening though.

If you have the option to change, some serialization formats offer more flexibility around versioning than XML, e.g, Protocol Buffers.

RagtimeWilly
  • 5,265
  • 3
  • 25
  • 41
  • If i de-serialize into old version and then do the conversion, that means I will have to keep the Original Geometry class as it is and duplicate it with a different name and do the conversion from Original to New on de-serialization. is that right? – WAQ Mar 03 '15 at 07:16
  • That's correct. Which is why I said it would be very difficult to maintain this approach if it wasn't just a once off. – RagtimeWilly Mar 03 '15 at 07:17