反序列化时忽略过时的字段

编程入门 行业动态 更新时间:2024-10-27 19:18:54
本文介绍了反序列化时忽略过时的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我整天都在寻找一种方法来实现这一目标而没有结果...

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.

更多推荐

反序列化时忽略过时的字段

本文发布于:2023-08-04 05:53:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1293533.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   序列化

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!