-->

Ignore obsolete field when deserializing

2019-07-06 21:33发布

问题:

I have been searching all day for a way to achieve this without result...

I am trying to deserialize an object. When I serialized it, I had a bool called (let's say) obsoleteBool. In the new version of the class I removed this bool, and I now have an error when deserializing (Field "obsoleteBool" not found).

It is very easy to add new fields between an old and a new version of a class. Even without using the [OptionalField] attribute... but how can I manage the removal of a field between an old and new version of a class?

回答1:

There are 3 possible solutions:

  • The simplest: Add the old Field to the New Version og the class
  • Custom code: Implement a custom deserializer
  • Extra work: Write a Conversion program that goes through all the serialized classes, that reads them With the old format and reserializes them With the New class definition.

In terms of business value the first option is probably preferable.