gpt4 book ai didi

json - 如何隐藏一些json作为响应?

转载 作者:行者123 更新时间:2023-12-01 10:33:38 29 4
gpt4 key购买 nike

我有一个基于 spring-data-rest 的模块。我收到此响应,例如,@Entity User .

网址:

http://localhost:8080/Product/rest/users

下面的响应(主要是那里有密码):
 {
"_embedded" : {
"users" : [ {
"def" : "dmityushin",
"delDate" : null,
"displayDef" : "Митюшин Дмитрий Александрович",
"email" : "dmitry.mityushin@megafon.ru",
"naviDate" : "2015-10-21T12:54:08.559+0000",
"naviUser" : "admin",
"phone" : null,
"pwd" : "266810e0707d7aeb8e838308aa248f3ea116e483",
"_links" : {
"self" : {
"href" : "http://localhost:8080/ProductCatalog/rest/2/users/308"
},
"user" : {
"href" : "http://localhost:8080/ProductCatalog/rest/2/users/308"
},
"pscUser" : {
"href" : "http://localhost:8080/ProductCatalog/rest/2/users/308/pscUser"
},
"pscBranch" : {
"href" : "http://localhost:8080/ProductCatalog/rest/2/users/308/pscBranch"
}
}
}, {
"def" : "grak",
"delDate" : null,
"displayDef" : "Григорий Рак",
"email" : "grigory.rak@MegaFon.ru",
"naviDate" : "2015-10-23T11:59:19.546+0000",
"naviUser" : "admin",
"phone" : null,
"pwd" : "c7f33616778ba938272eac0ca0a3364bfc17203d",
"_links" : {
"self" : {
"href" : "http://localhost:8080/ProductCatalog/rest/2/users/316"
},
"user" : {
"href" : "http://localhost:8080/ProductCatalog/rest/2/users/316"
},
"pscUser" : {
"href" : "http://localhost:8080/ProductCatalog/rest/2/users/316/pscUser"
},
"pscBranch" : {
"href" : "http://localhost:8080/ProductCatalog/rest/2/users/316/pscBranch"
}
}
}...OTHERS

我想隐藏密码和其他一些字段。我怎样才能做到这一点?我没有找到足够的信息。虽然看起来应该很简单。

我的实体代码:
@XmlRootElement
@XmlAccessorType(value = XmlAccessType.FIELD)
@Entity
@Table(name = "psc_users")
@NamedQuery(name = "User.findAll", query = "SELECT u FROM User u")
public class User implements Serializable {
private static final long serialVersionUID = 8885916014620036457L;

@Id
private static final String SEQUENCE_NAME = "psc_users_user_id_seq";
@Id
@GeneratedValue(...)
@GenericGenerator(...)
@Column(name = "USER_ID")
private Long userId;

@Column(name = "DEF")
private String def;

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DEL_DATE")
private Date delDate;

@Column(name = "DISPLAY_DEF", length = 60)
private String displayDef;

@Column(name = "EMAIL", length = 60)
private String email;

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "NAVI_DATE")
private Date naviDate;

@Column(name = "NAVI_USER")
private String naviUser;

@Column(name = "PHONE", length = 30)
private String phone;

@Column(name = "PWD", length = 40)
private String pwd;

//bi-directional many-to-one association to Branch
@ManyToOne(cascade = CascadeType.MERGE)
@JoinColumn(name = "BRNC_BRNC_ID", nullable = false)
private Branch pscBranch;

...some other fields

public User() {
}

...get() methods

}

抱歉我的英语不好,提前感谢(:

最佳答案

要隐藏某些字段,您可以在要隐藏的字段的 getter 上使用 @JsonIgnore,但不要忘记在该字段的 setter 上添加 @JsonSetter

关于json - 如何隐藏一些json作为响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38999942/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com