Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off getter/setter only for one instance non-final field? [Project Lombok]

public @Data class Person { ... }

As I know, when I mark a class with the @Data annotation, Lombok will provide getters for all fields, setters for all non-final fields. I want to turn off getter and setter only for one instance non-final field, how can I reach that?

What did I expect? To find an annotation like

@Setter(provide=false)
@Getter(provide=false)
private Map<...> dialogs;

or

@Data(excludeFields={"dialogs"})

I googled a lot and looked for on the official site, but I've found nothing.
Your help will be appreciated. Thank you.

like image 366
Andrew Tobilko Avatar asked Jun 15 '16 19:06

Andrew Tobilko


People also ask

How do you exclude getter and setter Lombok?

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.

How do you stop a getter setter?

Thus: you avoid getters and setters by thinking in terms of behavior, not in terms of state. Getters/setters manipulate state, from the "outside" (by doing avail = purse.

How do you override the getter method in Lombok?

From Lombok documentation: You can always manually disable getter/setter generation for any field by using the special AccessLevel. NONE access level. This lets you override the behaviour of a @Getter, @Setter or @Data annotation on a class.


1 Answers

You can use @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) on the field as described on the website.

Disclosure: I am a Lombok developer.

like image 195
Roel Spilker Avatar answered Sep 20 '22 21:09

Roel Spilker