0
点赞
收藏
分享

微信扫一扫

springboot中bean里大写的字段返回变成小写

凶猛的小白兔 2022-03-30 阅读 50
java后端

例如我的bean中有以下4个字段

private String code;

private String _TOKENUUMS;

private String TGC;

private String U;

在返回的json里只会显示{“code”:“xx”,“tgc”:“xx”,“u”:“xx”}
大小会变成小写,特殊符号开头的字段都不会显示,其原因是因为springboot在进行序列化和反序列时对字段进行了处理。
解决方案是:import com.fasterxml.jackson.annotation.JsonProperty;
在get方法上加上该注解@JsonProperty

private String code;

private String _TOKENUUMS;

private String TGC;

private String U;

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

@JsonProperty("_TOKENUUMS")
public String get_TOKENUUMS() {
return _TOKENUUMS;
}

public void set_TOKENUUMS(String _TOKENUUMS) {
this._TOKENUUMS = _TOKENUUMS;
}

@JsonProperty("TGC")
public String getTGC() {
return TGC;
}

public void setTGC(String TGC) {
this.TGC = TGC;
}

@JsonProperty("U")
public String getU() {
return U;
}

public void setU(String u) {
U = u;
}

返回json会变成{“code”:“xx”,"_TOKENUUMS":“xx”,“TGC”:“xx”,“U”:“xx”},完美解决问题!

举报

相关推荐

0 条评论