Exclude one element from Lombok model-wide setter and getter
Lets say you have a User model with Lombok modelwide @Getter and @Setter:
@Getter
@Setter
public class User {
@Id
private String id;
private String username;
private String email;
private String password;
}
setId(String id)
makes no sense.
Normally the id is set by the DB, so it makes no sense to set it.
So you can use @Setter(AccessLevel.NONE)
(or @Getter(AccessLevel.NONE)
) to exclude it from the Lombok setters (or getters)
@Getter
@Setter
public class User {
@Id
@Setter(AccessLevel.NONE)
private String id;
private String username;
private String email;
private String password;
}
(I found this answer on Stackoverflow by user Michael Piefel for this problem, thanks!