I understand that JsonProperty is used to map the variable to JSON key if the key is different from the variable.
Below is my sample POJO:-
public class JsonProperty {
@JsonProperty("studentId") //---------------variable
private String id;
@JsonProperty("studentId") //---------------getter
public String getIdValue() {
return id;
}
@JsonProperty("studentId") //---------------setter
public void setIdValue(String id) {
this.id = id;
}
}
JSON String: {"studentId" : "so1"}
Let's say that we are saving in DB using some JDBC code. I observed the below changes but could not accurately understand the behavior.
If @JsonProperty("studentId") is not used on a variable, getter and setter. observation: Noting is stored on DB.
If @JsonProperty("studentId") is used on variable alone. Observation: {"idValue" : "so1"} is stored in DB.
If @JsonProperty("studentId") is used on setter or getter. Observation: {"studentId" : "so1"} is stored in DB.
So, Could you explain what is the actual behavior that happens when we use JsonProperty on variable, getter and setter???