gpt4 book ai didi

java - org.springframework.data.domain.PageImpl 无法反序列化,当我想使用 findAll(Pageable pageable) 和注释 @Cacheable(spring cache) 时?

转载 作者:行者123 更新时间:2023-12-01 19:07:24 26 4
gpt4 key购买 nike

正如标题所说,

@CacheConfig(cacheNames = {"familyUserDao"})
public interface FamilyUserDao extends JpaRepository<FamilyUser,Long> {
@Override
@Cacheable(key = "methodName +#p0")
Page<FamilyUser> findAll(Pageable pageable);
}

但是当我使用如下方法时:

Page<FamilyUser> familyUserPage = familyUserDao.findAll(pageable);

错误消息:

org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Can not construct instance of org.springframework.data.domain.PageImpl: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: [B@7fae8571; line: 1, column: 46]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of org.springframework.data.domain.PageImpl: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: [B@7fae8571; line: 1, column: 46]
at org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer.deserialize(Jackson2JsonRedisSerializer.java:73),

有什么好的建议吗?任何建议将被认真考虑。非常感谢!

最佳答案

Jackson 模块要求您提供一个与 JSON 文件结构匹配的用于反序列化的类对象。解析错误几乎总是与以下任一相关:

  • 缺少或无法访问类属性
  • 缺少或默认构造函数

我相信在你的情况下,你很可能缺少一个适合反序列化此 JSON 的构造函数。 (猜测是因为您没有提供 PageImpl 类的源代码)

您应该能够通过使用 lombok@AllArgsConstructor 或添加一个新的构造函数来解决此错误,该构造函数的参数与相关 JSON 中的字段相匹配PageImpl 类。

关于java - org.springframework.data.domain.PageImpl 无法反序列化,当我想使用 findAll(Pageable pageable) 和注释 @Cacheable(spring cache) 时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59525175/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com