我在我的項目中使用 Spring Boot 和 lombok 并遇到了一些問題。我的課是這樣的:import org.springframework.data.annotation.Id;import org.springframework.data.mongodb.core.mapping.Document;import lombok.Data;@Data@Document(collection = "elements")public class ElementEntity { @Id private String id; // ...}現(xiàn)在,如果我使用 jackson ObjectMapper 創(chuàng)建我的 ElementEntity,我會收到以下運行時錯誤:com.fasterxml.jackson.databind.exc.InvalidDefinitionException:無法構造實例ElementEntity(無創(chuàng)建者,如默認構造,存在):無法從對象值反序列化(無基于委托或屬性的創(chuàng)建者)但是如果我添加@NoArgsConstructor來自 lombok 的我得到以下編譯錯誤:[錯誤] ElementEntity.java:[11,1] 構造函數(shù) ElementEntity() 已在類 ElementEntity 中定義它似乎@Document增加了一個,但可能只有包可見性。有沒有簡單的方法來解決這個問題,或者我必須手動添加一個 public no args 構造函數(shù)到 each @Document?
Lombok、Spring mongodb 和 jackson 構造函數(shù)問題
函數(shù)式編程
2021-09-03 13:02:40