redisson get()数据报错:

com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class java.lang.Object]: missing type id property ‘@class’

详细报错信息如下:
com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class java.lang.Object]: missing type id property '@class'
xxxx
xxxx
[ERROR] 2021-11-29 17:52:59.114 [redisson-netty-2-11] ErrorsLoggingHandler.exceptionCaught(47) - Exception occured. Channel: [id: 0x14385c74, L:/172.16.101.17:60939 - R:xxx.201.34.xxx/xxx.201.34.2xx:6379]
io.netty.handler.codec.DecoderException: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class java.lang.Object]: missing type id property '@class'
 at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 104]
xxx
xxx
Caused by: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class java.lang.Object]: missing type id property '@class'
报错原因:

json序列化转换失败,找不到名为“@class”的property

1. 解决方法一:

① 在实体类上添加注解:

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS,include = JsonTypeInfo.As.PROPERTY,property = "@class")

② 添加无参构造方法
③ 删除redis数据,重试

2. 解决方法二:

① 修改序列化器,支持以下序列化器,java的序列化使用SerializationCodeclQLPDhrpxJZNoprNBBTNApSwT2YQW1oT7q0BrD-HKUBIAA_660_1044.png_720x720g

② 实体类实现 Serializable 接口,添加serialVersionUID属性。
③ 删除redis数据,重试

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐