Access removed properties during deserialization

Feb 20, 2014 at 8:25 AM

is there a way to access the serialized values of removed properties during deserialization?

Assume a class like this:

public class Test {
public bool IsError {get;set;}

As the project evolves, I need to change the class like this:

public enum ResultCode

public class Test {
public ResultCode Result {get;set;}

When deserializing old objects I need to access the previous value of "IsError" and translate it to the new enum value. I know I could leave the "IsError" property and create a new getter/setter doing the conversion to the new enum, but I want to remove "IsError" to provide a clean API.

Is there any way to do this with SharpSerializer?

I have used JSON.Net a while ago. It has an "ExtraElements" attribute which can be used to collect all unknown elements in a separate JSON document, allowing to extract obsolete values by their name.

Mar 15, 2014 at 6:03 AM
Edited Mar 21, 2014 at 4:24 PM
Hi, since v. there is no NullReferenceException when deserializing unknown properties. These properties will be ignored.

Listing ignored properties is not implemented for the simple reason - if the old version does not know how to deserialize the objects, it will not know how to handle the unknown properties.

There would be too big overhead re-saving the unknown properties only to preserve the previous file format.

If you indeed need this functionality, I would suggest serializing a dictionary<key,value> where key and value are strings.