Is there a way to rename a getter method generated with lombok?

Viewed 329

I'm trying to figure out if there is a way to set the getter method name manually using lombok. Consider the following example:

@Getter
@Builder(setterPrefix = "with")
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Context {

    @Builder.Default
    private final boolean logReceivedMessages = false;
  
    ... many other fields ...

}

With the above example you are able to build the context like so:

context = Context.builder().withLogReceivedMessages(true/false).build;

and then use it as

if(context.isLogReceivedMessages()) {
   XYZ
} else {
   zyx
}

The name of the generated method is not really how I would word it and was wondering if there was a way to customize it? Is there an annotation which would allow me to name it to something like shouldLogReceivedMessages() instead of isLogReceivedMessages ? I can't seem to find that in the docs.

1 Answers

If this is the only method which needs name change, I would suggest to add another getter by your own inside Context; it will override lombok's getter.

But if you need lot more customisation in different methods then refer SO post mentioned by Teddy.

Related