Java反序列化java.lang.Integer - 异常 [英] Java Deserialization of java.lang.Integer - Exception

查看:836
本文介绍了Java反序列化java.lang.Integer - 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在反序列化 HashMap< String,Integer> 时收到以下异常:

Recieved the following exception when deserializing a HashMap<String, Integer>:

java.io.InvalidClassException: java.lang.Integer; local class incompatible: stream classdesc serialVersionUID = 1360826667802527544, local class serialVersionUID = 1360826667806852920

在同一台机器上使用相同的JRE进行序列化和反序列化。 JDK 1.6.0_12

Serialized and deserialized on the same machine, with the same JRE. JDK 1.6.0_12

推荐答案

从查看JDK源代码,1360826667806852920是正确的 serialVersionUID for Integer 。我无法使用 serialVersionUID 1360826667802527544在JDK中找到任何类。

From looking at the JDK source, 1360826667806852920 is the correct serialVersionUID for Integer. I wasn't able to find any classes in the JDK with the serialVersionUID 1360826667802527544.

有趣的是,搜索1360826667802527544在Google上出现了一些有这个问题的人,特别是这个Sun论坛上的主题。问题是该人在字符串中存储字节,并且序列化数据被破坏。由于你得到相同的 serialVersionUID ,你似乎很可能遇到类似的问题。

Interestingly, searching for 1360826667802527544 on Google turned up a few other people with this problem, notably this thread on Sun's forums. The problem there was that the person was storing bytes in a String, and the serialized data was getting mangled. Since you're getting the same serialVersionUID it seems very likely that you're running into a similar problem.

永远不要在 String 中存储字节。使用字节数组或用于保存字节的类,而不是字符。

Never store bytes in a String. Use a byte array or a class designed to hold bytes, not chars.

这篇关于Java反序列化java.lang.Integer - 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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