0

I have a REST payload which has a boolean property. And am using Lombok @Data since it is handy. However this is resulting in unexpected behaviour while working with JAX-RS. Below is the POJO used as REST payload:

@Data
public class Foo implements Serializable { 
    private long id;
    private String bar;
    private boolean isDefault;
}

Lombok adds below getter and setter:

isDefault()   // getter
setDefault()  // setter

And I was using below paylod to make POST call:

 {
     "id": 1,
     "bar": "Something interesting",
     "isDefault": true
 }

Now is the real problem, while making a REST call JAX-RS is looking for setIsDefault() and would never set the value for isDefault.

vinodpthmn
  • 1,062
  • 14
  • 28
  • 1
    change the field `isDefault` to `default` – Phenomenal One Jun 25 '19 at 09:14
  • @MaruthiAdithya Will not work. The getter will be `getDefault` not `getIsDefault`. Either change the field to the wrapper class `Boolean` or don't rely on lombok to generate them automatically. – Michael Jun 25 '19 at 09:17
  • @MaruthiAdithya "default" is a keyword in Java. However a variable name without "is" prefix would solve the problem. I am looking for any alternate to keep "is". – vinodpthmn Jun 25 '19 at 11:25
  • The workaround would be to either rename the field or use Boolean instead of primitive (see https://www.baeldung.com/lombok-getter-boolean). Thanks @Michael for refering to the other question. – vinodpthmn Jun 25 '19 at 11:29

0 Answers0