Want to add @JsonIgnore property to password in Json response

I want to add @JsonIgnore of Jackson in the Password property for the user domain so that I can send the Json With password and it saves my data in the database, but in response I do not want to show the password.

How can I achieve this, please help me.

I tried to use it at the domain level of the User where the properties are defined, but it completely ignores the property in the getter and setter methods.

I tried this

private String password;
 @JsonIgnore
        public String getPassword() {
            return this.password;
        } 
+4
source share
2 answers

Try to use @JsonIgnoreand @JsonPropertyin your class:

private String password;

@JsonIgnore
public String getPassword() {
    return password;
}

@JsonProperty
public void setPassword(String password) {
    this.password = password;
}
+10
source
+1

All Articles