Ignore obsolete field when deserializing

耗尽温柔 提交于 2019-12-12 14:34:09

问题


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.



来源:https://stackoverflow.com/questions/25108395/ignore-obsolete-field-when-deserializing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!