Can i use @JsonIgnore with @Getter annotation from lombok without explicitly define the getter, because i have to use this JsonIgnore while serializing the object but while deserializing, the JsonIgnore annotation must be ignore so the field in my object must not be a null.
@Getter
@Setter
public class User {
private userName;
@JsonIgnore
private password;
}
i know, just by define the JsonIgnore on the getter of password i can prevent my password to be serialized but for that i have to explicitly define the getter thing that i don't want. Any idea please, Any help will be appreciated.
To put the @JsonIgnore to the generated getter method, you can use onMethod = @__( @JsonIgnore ). This will generate the getter with the specific annotation. For more details check http://projectlombok.org/features/GetterSetter.html
@Getter
@Setter
public class User {
private userName;
@Getter(onMethod = @__( @JsonIgnore ))
@Setter
private password;
}