2

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.

  • you could change boolean to Boolean, take a look at https://stackoverflow.com/questions/39381474/cant-make-jackson-and-lombok-work-together. – Turo Nov 24 '20 at 08:42

1 Answers1

5

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

Vlad L
  • 1,544
  • 3
  • 6
  • 20