zoukankan      html  css  js  c++  java
  • Redis | 使用redis存储对象反序列化异常SerializationFailedException

    案例

    使用Redis进行对象存储,在处理业务逻辑的时候,丛Redis获取对象发现反序列化失败,抛出如下异常:

    Caused by: org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.InvalidClassException: weixin.popular.bean.token.Token; local class incompatible: stream classdesc serialVersionUID = -584152862903853930, local class serialVersionUID = 8841433872811285796
        at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:82)
        at org.springframework.data.redis.core.AbstractOperations.deserializeValue(AbstractOperations.java:318)
        at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:58)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:207)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169)
        at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:91)
        at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:43)
        at com.ppmoney.geedai.wechat.service.wechat.impl.GetAccessTokenServiceImpl.get(GetAccessTokenServiceImpl.java:37)
        at com.ppmoney.geedai.wechat.service.wechat.impl.CustomMsgServiceImpl.send(CustomMsgServiceImpl.java:32)
        ... 82 common frames omitted
    Caused by: org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.InvalidClassException: weixin.popular.bean.token.Token; local class incompatible: stream classdesc serialVersionUID = -584152862903853930, local class serialVersionUID = 8841433872811285796
        at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:78)
        at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:36)
        at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:80)
        ... 90 common frames omitted
    Caused by: java.io.InvalidClassException: weixin.popular.bean.token.Token; local class incompatible: stream classdesc serialVersionUID = -584152862903853930, local class serialVersionUID = 8841433872811285796
        at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:616)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1623)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
        at org.springframework.core.serializer.DefaultDeserializer.deserialize(DefaultDeserializer.java:70)
        at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:73)
        ... 92 common frames omitted

    解决方案

    经排查,原因是存放的对象忘了添加序列化号,导致存储的序列化编号和反序列化编号不一致,所以反序列化异常。

    这里写图片描述

    只需要把序列化编号添加上即可,记得清理Redis缓存:

    private static final long serialVersionUID = 8841433872811285796L;

    这里写图片描述

  • 相关阅读:
    乘法相关
    hdu 1211 RSA (逆元)
    hdu 1811 Rank of Tetris (拓扑 & 并查集)
    hdu 2153 仙人球的残影
    hdu 1426 Sudoku Killer (dfs)
    hdu 2510 符号三角形 (DFS+打表)
    zoj 1002 Fire Net (二分匹配)
    hdu 1172 猜数字
    hdu 1728 逃离迷宫 (bfs)
    《Effective C++》笔记:III(转载)
  • 原文地址:https://www.cnblogs.com/evan-liang/p/12233940.html
Copyright © 2011-2022 走看看