Lombok, Spring mongodb and jackson Constructor problem

Thomas :

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?

benjamin c :

Its a bug in lombok 1.16.22, try upgrading to 1.18.0,

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.0</version>
    <scope>provided</scope>
</dependency>

Read

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=115591&siteId=1