簡體   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)?

正如標題所說,

@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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM