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
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ToString
public class DefaultModel {
private String name;
@Setter(AccessLevel.NONE)private String age;
public void setAge(String age) {
if(age==null||age.trim().isEmpty()||age.equals("null")) {
this.age="10";
}else {
this.age=age;
}
}
}
Working scenarios:
{
"name":"some",
"age":null
}
{
"name":"some",
"age":"null"
}
{
"name":"some",
"age":" "
}
Failed Scenario :
{
"name":"some"
}
Output:
DefaultModel(name=some, age=null)
And i'm following this as reference also here, but no luck so far