我整天都在寻找一种方法来实现这一目标而没有结果...
I have been searching all day for a way to achieve this without result...
我正在尝试反序列化一个对象.当我序列化它时,我有一个叫做(叫)obsoleteBool的布尔值.在该类的新版本中,我删除了该布尔,然后在反序列化时遇到错误(找不到字段"obsoleteBool").
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).
在类的旧版本和新版本之间添加新字段非常容易.即使不使用[OptionalField]属性,但是如何管理类的旧版本和新版本之间的字段删除?
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?
推荐答案有3种可能的解决方案:
There are 3 possible solutions:
- 最简单的方法:将旧字段添加到类的新版本中
- 自定义代码:实施自定义反序列化器
- 额外的工作:编写一个转换程序,该程序遍历所有序列化的类,以旧格式读取它们,并使用新的类定义重新序列化它们.
就商业价值而言,第一种选择可能更可取.
In terms of business value the first option is probably preferable.
更多推荐
反序列化时忽略过时的字段
发布评论