Suppose we have this variable
@JsonProperty(« prop1 »)
private String prop1;
and it’s getter an setter
@JsonProperty(« prop1 »)
public String getProp1() {
return role;
}
@JsonProperty(« prop1 »)
public void setProp1(String prop1) {
this.prop1= prop1;
}
here we serialize and deserialisze our prop1 cleaner from the classe that embedd it
How to say don’t deserializ/get ( from pojo to json )?
//remove @JsonProperty (only one propagate from the variable gette setter vice versa for the 3 )
private String prop1;
and it’s getter an setter
@JsonIgnore //make it on getter beacause the getter is used to extract it from pojo to json
public String getProp1() {
return role;
}
@JsonProperty(« prop1 ») //we remove it from prop1 that it will be only tied to setter and prop1 , i fwe let it on prop1 it will propagate it to getter and setter and our @JsonIgnore will have no effect
public void setProp1(String prop1) {
this.prop1= prop1;
}
@JsonIgnore
: simple annotation to use for ignoring specified properties:
- Only needs to be added to one of accessors/mutators (field, getter/setter, constructor parameter), but will have effect on the « whole » property: that is, adding annotation to a « getter » will also disable « setter »
- … unless « setter » has
@JsonProperty
, in which case this is considered a « split property » with enabled « setter » but no « getter » (« read-only », so that property may be read from input, but is not written output)
- … unless « setter » has
///—-