I am using Spring Boot and lombok in my project and encounter some issues with it. My class looks like this:
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;
// ...
}
Now, if I use jackson ObjectMapper to create my ElementEntity, I get the following runtime error:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of
ElementEntity
(no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
But if I add the @NoArgsConstructor
from lombok I get the following compilation error:
[ERROR] ElementEntity.java:[11,1] constructor ElementEntity() is already defined in class ElementEntity
It seems @Document
adds one but probably only with package visibility. Is there an easy way to solve this, or I have to manually add a public no args constructor to every @Document
?