安卓:如果我添加的serialVersionUID老序列化对象会发生什么情况? [英] Android: what happens if I add serialVersionUID to old serializable objects?

查看:260
本文介绍了安卓:如果我添加的serialVersionUID老序列化对象会发生什么情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你把一个旧的序列化对象,从未有过的serialVersionUID明确规定,并添加的serialVersionUID到该对象会发生什么情况?在我看来,下一次该应用程序是由最终用户更新,它会尝试从光盘反序列化数据,找出了serialVersionUID的不匹配,覆盖从服务器/ DB新的数据/数据​​不管以后你再罚款。我是正确的这一假设?是否有进一步的问题,我应该警惕在做这个?

 私有类X实现Serializable {...

私有静态最后长的serialVersionUID = 0L;
 

解决方案
  1. 如果你给它显示运行的类用serialver 工具,因为它现在是,什么也没有发生相同的值。
  2. 如果你给它一个不同的值,现有的串行数据流,包括该类将失败与 InvalidClassException 进一步deserializations。
  

在我看来,下一次该应用程序是由最终用户更新,它会尝试序列化从光盘数据

正确的。

  

找出了serialVersionUID的不匹配

只有当它真的不匹配。如果你按照上面的建议,它将匹配。

  

覆盖从服务器/数据库/不管

新数据数据

不正确的。见上面。

  

和之后,你会感觉良好。

没有。

  

我是正确的这一假设?

没有。

What happens if you take an old serializable object that never had serialVersionUID explicitly specified, and add serialVersionUID to that object? It seems to me that the next time the app was updated by endusers it would try to deserialize data from disc, find out that the serialVersionUID didn't match, overwrite the data with new data from the server/db/whatever and after that you're fine. Am I correct in this assumption? Are there further issues I should be wary of in doing this?

private class X implements serializable {...

private static final long serialVersionUID = 0L;

解决方案

  1. If you give it the same value that is shown by running the serialver tool on the class as it is now, nothing happens.
  2. If you give it a different value, further deserializations of existing serial streams including that class will fail with an InvalidClassException.

It seems to me that the next time the app was updated by endusers it would try to deserialize data from disc

Correct.

find out that the serialVersionUID didn't match

Only if it really didn't match. If you follow the advice above, it will match.

overwrite the data with new data from the server/db/whatever

Incorrect. See above.

and after that you're fine.

No.

Am I correct in this assumption?

No.

这篇关于安卓:如果我添加的serialVersionUID老序列化对象会发生什么情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆