In a Spring Boot applicaion with AngularJS frontend, a "Pin" field value has to be blackened on serialization, i.e., if the Pin field value is null in the POJO, the according JSON field has to remain blank; if the field value contains data, it has to be replaced with a "***" string.
Does Jackson provide a feature to get this done?
You can do it easily like following without any Custom Serializer
public class Pojo {
@JsonIgnore
private String pin;
@JsonProperty("pin")
public String getPin() {
if(pin == null) {
return "";
} else {
return "***";
}
}
@JsonProperty("pin")
public void setPin(String pin) {
this.pin = pin;
}
@JsonIgnore
public String getPinValue() {
return pin;
}
}
You can use Pojo.getPinValue()
to get the exact value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With