Maria Rona
Maria Rona

Reputation: 179

Lombok @Data annotation changes the name of a field from isood to good

I have this DTO which uses @Data annotation of lombok in order to generate getters and setters:

@Data
public class SomeDto {

  protected boolean isGood;
}

The weird thing is that now my getter has been renamed from getisGood() to isGood() and the setter has the name setGood() instead of setIsGood(). Example:

SomeDto somedto = new SomeDto()
somedto.setGood(false) //sets the value to false - should have been setIsGood
somedto.isGood() //return false - should have been getIsGood

Also when I make a request on the endpoint where I use this DTO in the JSON returns:

{"good": false}

whereas is should has been :

{"isGood": false}

Anyone has any idea what the problem is? I have a suspicion that the "is" in the beginning of isGood creates maybe a confusion for lombok. I appreciate any help you can provide.

Upvotes: 2

Views: 2076

Answers (1)

Vlad L
Vlad L

Reputation: 1694

I guess the convention is that for a boolean, the getter is called isGood, while the setter is setGood. So your boolean is expected to be called just "good".

Here is one discussion

Also in the documentation :)

 lombok.getter.noIsPrefix = [true | false] (default: false)
    If set to true, getters generated for boolean fields will use the get prefix instead of the defaultis prefix, and any generated code that calls getters, such as @ToString, will also use get instead of is 

Docs

Upvotes: 6

Related Questions