One of my POJOs has a Boolean object field to permit NULLS in the database (a requirement). Is it possible to use the @Data Lombok annotation at class level yet override the getter for the Boolean field? The default it generates is getXXX method for the Boolean field. I wish to override it as isXXX()?
Thanks,
Paddy
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.
Overview. You can annotate any field with @Getter and/or @Setter , to let lombok generate the default getter/setter automatically. A default getter simply returns the field, and is named getFoo if the field is called foo (or isFoo if the field's type is boolean ).
@Data is a convenient shortcut annotation that bundles the features of @ToString , @EqualsAndHashCode , @Getter / @Setter and @RequiredArgsConstructor together: In other words, @Data generates all the boilerplate that is normally associated with simple POJOs (Plain Old Java Objects) and beans: getters for all fields, ...
It's a bit verbose, but you can provide your own isXXX
, and then use AccessLevel.NONE
to tell Lombok not to generate the getXXX
:
@Data public class OneOfPaddysPojos { // ... other fields ... @Getter(AccessLevel.NONE) private Boolean XXX; public Boolean isXXX() { return XXX; } }
(And hey, at least it's not quite as verbose as if you weren't using Lombok to begin with!)
I think if you switch your field from Boolean X
to boolean X
than lombok generate a getter isX()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With