想要在响应Json的密码上添加@JsonIgnore属性 [英] Want to Add @JsonIgnore property on Password in response Json

查看:222
本文介绍了想要在响应Json的密码上添加@JsonIgnore属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户域的密码属性中添加Jackson的@JsonIgnore,这样我必须能够发送带有密码的Json并将数据保存在数据库中,但作为回应我不想显示密码。

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 response I don't want to show the password.

我如何实现这一点请帮助我。

How can I acheive this please help me.

我试图在域名级别使用它用户定义了属性,但它完全忽略了getter和setter方法中的属性。

I tried to use it at the Domain level of the User where the properties are defined but it Totally Ignore the property in the getter and setter methods.

我试过这个

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


推荐答案

尝试同时使用 @JsonIgnore <您班上的code> @JsonProperty ,如下所示:

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;
}

这篇关于想要在响应Json的密码上添加@JsonIgnore属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆