2
votes

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?

2
whats the version of lombok ?benjamin c
@benjaminc I'm currently using 1.16.22Thomas

2 Answers

5
votes

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

2
votes

Try to change id field definition to this:

@Id
@Getter
@Setter
private String id;