[英]org.springframework.data.domain.PageImpl can't be deserialized,when i want to use findAll(Pageable pageable) with annotation @Cacheable(spring cache)?
As the title says,正如标题所说,
@CacheConfig(cacheNames = {"familyUserDao"})
public interface FamilyUserDao extends JpaRepository<FamilyUser,Long> {
@Override
@Cacheable(key = "methodName +#p0")
Page<FamilyUser> findAll(Pageable pageable);
}
But when I use this method like below :但是当我像下面这样使用这种方法时:
Page<FamilyUser> familyUserPage = familyUserDao.findAll(pageable);
Error message:错误信息:
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),
Is there any good advice provided?有什么好的建议吗? Any advice will be appreciated.
任何建议将被认真考虑。 Thank you very much!
非常感谢!
The Jackson
module requires you to provide a class object for deserialization that matches the structure of your JSON file. Jackson
模块要求您提供一个与 JSON 文件结构相匹配的用于反序列化的类对象。 The parsing errors are almost always related with either:解析错误几乎总是与以下任一相关:
I believe in your case you are most probably missing a constructor that is suitable to deserialize this JSON.我相信在您的情况下,您很可能缺少适合反序列化此 JSON 的构造函数。 (guessing as you have not provided the source code for the PageImpl class)
(猜测是因为您没有提供 PageImpl 类的源代码)
You should be able to solve this error by either using lombok
's @AllArgsConstructor
or by adding a new constructor which parameters match the fields in the JSON in question inside the PageImpl class.您应该能够通过使用两种解决这个错误
lombok
的@AllArgsConstructor
或通过添加一个新的构造函数的参数匹配在JSON中的字段有问题的PageImpl类中。
DTO pojo class must should implements serialiazable DTO pojo 类必须实现可序列化
public class FamilyUserDTO implements Serializable {
//members
// setters and getters
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.