Want to Add @JsonIgnore property on Password in response Json

后端 未结 4 1022
有刺的猬
有刺的猬 2021-02-13 15:33

I want to add @JsonIgnore of Jackson On the Password property of User domain such that I must be able to send the Json With password and It saves my data in Database but in resp

相关标签:
4条回答
  • 2021-02-13 16:14

    In my case it helped to do it like that:

    @JsonProperty
    private String password;
    
    @JsonIgnore
    public String getPassword() {
        return password;
    }
    
    public void setPassword(String password) {
        this.password = password;
    }
    
    0 讨论(0)
  • 2021-02-13 16:21

    I think you should use DTO Pattern to set / change password.

    0 讨论(0)
  • 2021-02-13 16:30

    Try using both @JsonIgnore and @JsonProperty in your class like this:

    private String password;
    
    @JsonIgnore
    public String getPassword() {
        return password;
    }
    
    @JsonProperty
    public void setPassword(String password) {
        this.password = password;
    }
    
    0 讨论(0)
  • 2021-02-13 16:32

    You can do it this way too if you don't want to manually create the getters/setters (eg. when using lombok's @Data)

    @JsonProperty(access = Access.WRITE_ONLY)
    private String password;
    
    0 讨论(0)
提交回复
热议问题