Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories


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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
406 views
Welcome To Ask or Share your Answers For Others

1 Answer

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!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...