org.springframework.data.redis.serializer.SerializationException: Could not read JSON

org.springframework.data.redis.serializer.SerializationException: Could not read JSON: failed to lazily initialize a collection, could not initialize proxy - no Session (through reference chain: com.opt.otherSys.apps.domain.GMAnswerPaperHeaderEntity[“answerDet”]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection, could not initialize proxy - no Session (through reference chain: com.opt.otherSys.apps.domain.GMAnswerPaperHeaderEntity[“answerDet”])

Hibernate多表关联@OneToMany 查询结果存在Redis,再次取值出现Could not read JSON: failed to lazily initialize a collection, could not initialize proxy - no Session异常

问题原因这里不再解释,解决方案就是查询结果实例化(在session会话存在时读取数据),可以选择先转JSON,然后再转对象的方式,

org.springframework.data.redis.serializer.SerializationException是一个反序列化异常,表示在将JSON字符串转换为对象时出现了问题。具体地说,"Unrecognized field"意味着JSON字符串中包含了无法识别的字段。 这个异常通常发生在使用Spring框架的Redis序列化器时,它试图将JSON字符串反序列化为Java对象。在你提供的引用中,出现了两个例子,它们都是由于JSON字符串中的字段与Java对象的属性不匹配而引发了异常。 为了解决这个问题,你可以采取以下几个方法: 1. 使用@JsonIgnoreProperties(ignoreUnknown = true)注解 这个注解可以在类级别上使用,用于告诉Jackson JSON库在反序列化过程中忽略未知的JSON字段。在你的问题中,你可以在相关的Java类上加上这个注解以忽略无法识别的字段。 2. 使用@JsonIgnore注解 另一种解决方法是在相关的setter、getter或is方法上使用@JsonIgnore注解。这个注解可以用来忽略指定的属性,在反序列化时不会将其考虑在内。 综上所述,你可以根据具体情况选择其中一种方法来解决org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized field异常。通过使用@JsonIgnoreProperties(ignoreUnknown = true)注解或在相关方法上使用@JsonIgnore注解,你可以告诉序列化器忽略无法识别的字段,从而避免这个异常的发生。 : org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized field : org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized field "accountNonLocked" : 解决办法:在类加上注解@JsonIgnoreProperties(ignoreUnknown = true)忽略实体中没有对应的json的key值,或者在set、get或is开头的方法上加上@JsonIgnore注解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值