Could not read JSON: Cannot construct instance of‘‘类名““(no Creators, like default construct, exist)

142 篇文章 46 订阅 ¥9.90 ¥99.00
在使用Spring Data Redis时遇到了一个错误:Cannot construct instance of 类名。问题出在从Redis中反序列化对象时,由于实体类缺少无参构造函数导致。尽管实体类实现了序列化接口并包含get/set方法,但仍然需要明确地提供无参构造函数以供序列化库创建对象。添加无参构造函数后,问题得到解决。
摘要由CSDN通过智能技术生成

使用redis存对象的时候报错了,报错信息全部的报错信息如下:

org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Cannot construct instance of `com.xkcoding.cache.redis.entity.User` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

 

是将redis中值转化为对象的时候出错了,一开始一直以为是,使用的RedisTemplate有问题,使用的serializer用错了, 配置如下:

 
  1.  

     /**
         * 默认情况下的模板只能支持RedisTemplate<String, String>,也就是只能存入字符串,因此支持序列化
         */
        @Bean
        public   RedisTemplate<String, Serializable>  redisCacheTemplate(LettuceConnectionFactory redisConnectionFactory) {
            RedisTemplate<String, Serial
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hello_world!

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值