在以下情况下向后兼容 xstream
我有以下课程。
class SimpleDate {
private final int year; /* ? */
private final int month; /* 0 ~ 11 */
private final int date; /* 1 ~ 31 */
}
现在,我计划将课程重构为。
class SimpleDate {
private final int year; /* ? */
private final int month; /* 1 ~ 12!!!!! <-- change from 0 based to 1 based */
private final int day; /* 1 ~ 31 */
}
为了解决变量重命名问题,我将使用别名。
xStream.aliasField("date", SimpleDate.class, "day");
但是,我如何知道我正在读取旧的 XML 文件,并且我将为新读取的月份字段+1,将其从基于 0 更改为基于 1?
I had the following class.
class SimpleDate {
private final int year; /* ? */
private final int month; /* 0 ~ 11 */
private final int date; /* 1 ~ 31 */
}
Now, I plan to re-factor the class to.
class SimpleDate {
private final int year; /* ? */
private final int month; /* 1 ~ 12!!!!! <-- change from 0 based to 1 based */
private final int day; /* 1 ~ 31 */
}
To solve the the variable renaming issues, I will use alias.
xStream.aliasField("date", SimpleDate.class, "day");
However, how can I know I am reading an old XML file, and I will +1 for the newly read month field, to change it from based 0 to based 1?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
xstream 常见问题解答 http://x-stream.github.io/faq.html 有关于如何处理不同版本的部分。
The xstream FAQ http://x-stream.github.io/faq.html has a section about how tp deal with different versions.