I want to use a data class in Lombok. Since it has about a dozen fields, I annotated it with @Data
in order to generate all the setters and getter. However there is one special field for which I don't want to the accessors to be implemented.
How does Lombok omit this field?
with lombak 1.8.12, this worked for me
@Getter(value = lombok.AccessLevel.NONE)
@Setter(value = lombok.AccessLevel.NONE)
private int password;
If you have setter and getter as private it will come up in PMD checks.
According to @Data description you can use:
All generated getters and setters will be public. To override the access level, annotate the field or class with an explicit @Setter and/or @Getter annotation. You can also use this annotation (by combining it with AccessLevel.NONE) to suppress generating a getter and/or setter altogether.
User the below code for omit/excludes from creating setter and getter. value key should use inside @Getter
and @Setter
.
@Getter(value = AccessLevel.NONE)
@Setter(value = AccessLevel.NONE)
private int mySecret;
Spring boot 2.3 version, this is working well.
Source: Stackoverflow.com