![](/img/trans.png)
[英]org.springframework.data.domain.PageImpl cannot be cast to
[英]org.springframework.data.domain.PageImpl can't be deserialized,when i want to use findAll(Pageable pageable) with annotation @Cacheable(spring cache)?
正如标题所说,
@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类中。
DTO pojo 类必须实现可序列化
public class FamilyUserDTO implements Serializable {
//members
// setters and getters
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.