简体   繁体   English

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

[英]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:解析错误几乎总是与以下任一相关:

  • missing or unreachable class properties缺少或无法访问的类属性
  • missing or default constructor缺少或默认构造函数

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.

相关问题 org.springframework.data.domain.PageImpl 不能转换为 - org.springframework.data.domain.PageImpl cannot be cast to 我们可以排序列表吗<T>从 Spring 启动 Pageable 还是从 PageImpl 排序页面? - Can we sort List<T> from Spring boot Pageable or sort page from PageImpl? Jackson 和 Feign 无法反序列化 Spring 的 org.springframework.data.domain.Sort - Jackson with Feign can't deserialized Spring's org.springframework.data.domain.Sort 在 Spring 中使用带有 Pageable 的 findAll 的最佳方法是什么? - What is the best way to use findAll with Pageable in Spring? 无法实例化[org.springframework.data.domain.Pageable]:指定的类是接口 - Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface 找不到接口 org.springframework.data.domain.Pageable 的主要或默认构造函数 - No primary or default constructor found for interface org.springframework.data.domain.Pageable 调用使用@Cacheable注释的方法(org.springframework.cache.annotation.Cacheable) - Calling a method annotated with @Cacheable (org.springframework.cache.annotation.Cacheable) 覆盖Pageable findAll,用于在Spring Data Rest中选择较少的列 - Override Pageable findAll for selecting fewer columns in Spring Data Rest 如何在Spring Data中使用Pageable运行运行时生成的查询? - How can I run a runtime generated query with Pageable in Spring Data? Spring Data JPA:具有Specification和Pageable的findAll在计数查询上失败 - Spring Data JPA: findAll with Specification and Pageable fails on count query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM