UserCache.getUser方法出现的反序列化问题

Blade 已结 2 145
yizd
yizd 2026-01-14 11:49

一、该问题的重现步骤是什么?

1. 在User类中新增字段并使用maven deploy为最新版本,在redis中缓存了包含此新字段的User数据

2. 在使用旧版本的user-api的服务中,使用了UserCache.getUser方法的地方会报org.springframework.data.redis.serializer.SerializationException: Could not read JSON:Unrecognized field "xxx" (class org.springblade.system.pojo.entity.User)错误

3.目前通过升级最新user-api版本解决了此问题


二、你期待的结果是什么?实际看到的又是什么?

期待:User类新增字段不影响UserCache.getUser方法

实际:使用了UserCache.getUser方法的地方会报org.springframework.data.redis.serializer.SerializationException: Could not read JSON:Unrecognized field "xxx" (class org.springblade.system.pojo.entity.User)错误


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

bladex 4.3.0.RELEASE

win10

四、请提供详细的错误堆栈信息,这很重要。

org.springframework.data.redis.serializer.SerializationException: Could not read JSON:Unrecognized field "accountFlag" (class org.springblade.system.pojo.entity.User), not marked as ignorable (36 known properties: "deptId", "nation", "realName", "name", "isDeleted", "avatar", "homeDistrictCode", "id", "email", "createDept", "passwordHmac", "tenantId", "sex", "createUser", "companyName", "createTime", "code", "phone", "roleId", "status", "updateUser", "phoneHmac", "updateTime", "homeCityCode", "idNo", "birthday", "password", "userType", "userCategory", "account", "passwordUpdateTime", "idType", "homeProvinceCode", "postId", "applicationReason", "position"])

 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 1007] (through reference chain: org.springblade.system.pojo.entity.User["accountFlag"]) 

at org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer.deserialize(GenericJackson2JsonRedisSerializer.java:292) ~[spring-data-redis-3.2.12.jar:3.2.12]

at org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer.deserialize(GenericJackson2JsonRedisSerializer.java:261) ~[spring-data-redis-3.2.12.jar:3.2.12]

at org.springframework.data.redis.serializer.DefaultRedisElementReader.read(DefaultRedisElementReader.java:46) ~[spring-data-redis-3.2.12.jar:3.2.12]

at org.springframework.data.redis.serializer.RedisSerializationContext$SerializationPair.read(RedisSerializationContext.java:277) ~[spring-data-redis-3.2.12.jar:3.2.12]

at org.springframework.data.redis.cache.RedisCache.deserializeCacheValue(RedisCache.java:390) ~[spring-data-redis-3.2.12.jar:3.2.12]

at org.springframework.data.redis.cache.RedisCache.lookup(RedisCache.java:209) ~[spring-data-redis-3.2.12.jar:3.2.12]

at org.springframework.cache.support.AbstractValueAdaptingCache.get(AbstractValueAdaptingCache.java:58) ~[spring-context-6.1.15.jar:6.1.15]

at org.springblade.core.cache.utils.CacheUtil.get(CacheUtil.java:219) ~[blade-starter-cache-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springblade.core.cache.utils.CacheUtil.get(CacheUtil.java:197) ~[blade-starter-cache-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springblade.system.cache.UserCache.getUser(UserCache.java:76) ~[blade-user-api-1.0.8.RELEASE.jar:na]

五、若有更多详细信息,请在下面提供。

2条回答
  •  tongyi
    tongyi (楼主)
    2026-01-16 11:27

    把缓存数据改成JSON格式,不管新增还是删除字段,对反序列化不影响

提交回复