![](/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.