【问题标题】:Getting java.io.InvalidClassException: local class incompatible: even with serialVersionUID获取 java.io.InvalidClassException:本地类不兼容:即使使用 serialVersionUID
【发布时间】:2018-04-21 05:48:26
【问题描述】:

开发人员在实现Serializable 接口的类中声明了这一点。

XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "http://employer.webservicedto.dto.com", name = employerRequestDTO")
public class EmployerRequestDTO implements Serializable{

 private static final long serialVersionUID = -3956940714175091216L;
 // all private instance variables with getters & setters

}

堆栈跟踪说 -

decodeRequestData - decodeReqData() 中的异常: java.io.InvalidClassException: 雇主请求DTO;当地的 类不兼容:流 classdesc serialVersionUID = -3551130751187195282,本地类serialVersionUID = -3956940714175091216

/**
     * This method de-serializes user's request-data to return respective DTOs
     */
    public static Object decodeRequestData(String requestData, String userType){
        Object userRequestDTO = null;
        try{    
            byte[] b = Base64.decode(requestData);
            ByteArrayInputStream bi = new ByteArrayInputStream(b);
            ObjectInputStream si = new ObjectInputStream(bi);

【问题讨论】:

标签: java


【解决方案1】:

看起来该类已序列化,并将 serialVersionUID 值设置为 -3551130751187195282,然后在源中更新该类并将 serialVersionUID 设置为 -3956940714175091216。所以现在该类的源与被序列化的版本不兼容。 您可以尝试将serialVersionUID 设置回-3551130751187195282 - 但我会小心的。试着找出为什么这个值被改变了——也许在类源中有其他的改变使得它不能与以前的序列化版本一起使用。

【讨论】:

  • 谢谢,这是我的问题。我曾假设使用“新”单例(这是我的错误恢复)重新序列化会修复它,但我必须明确删除现有文件。
猜你喜欢
  • 2015-07-21
  • 2020-01-06
  • 1970-01-01
  • 2012-01-28
  • 1970-01-01
  • 2015-02-07
  • 1970-01-01
  • 2012-01-10
相关资源
最近更新 更多