Skip to content
Advertisement

How to override Lombok Setter methods

I’m using lombok in my project and generation Setters and Getters using @Setters and @Getters annotations on top of POJO class. I’m trying to override setters method of a property but it’s not working

I want to check if JSON property is Empty or Null i want to set default value in Setter method

JavaScript

Working scenarios:

JavaScript

Failed Scenario :

JavaScript

Output:

JavaScript

And i’m following this as reference also here, but no luck so far

Advertisement

Answer

Either you just hit a bug I’ve never seen or you’re testing it wrong.

An annotation like

JavaScript

on the field level indeed stops the setter from being generated. But given that you’re defining a setter, you don’t even need it. An explicit @Setter stops the generation, too.

I’ve just tried your example using Eclipse 4.7.3a and Lombok 1.18.0 and your (buggy) setter gets called. I’ve been using Lombok a lot over a few years and never encountered such a bug.

Most probably the problem is that your JSON deserializer does not use setters at all. I guess, you’re testing something like

JavaScript

instead of testing the setter directly. And that’s the problem.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement