【发布时间】:2021-03-12 16:42:59
【问题描述】:
我遇到了一个问题,即 Spring 向我的响应对象添加了额外的键。我附上了下面的回复(Response-2)。
我也尝试删除 @JsonProperty 但这也不起作用,因为所有键都是小写的。
想要的结果:我希望我的所有键都应该是大写的,因为我已经在 POJO 类中声明了它们。我将通过 Kafka 发送 JSON。
没有@JsonProperty:
{
"watchlsttype": null,
"acctno": null,
"chg_TYPE": null,
"status": null,
"rec_TYPE": null,
"lstchgtimestamp": null,
"expirytimestamp": null
}
API:
@GetMapping(value = "/dummyAPI")
public Object dummyAPI() throws Exception {
return new InteracAccountAllowList();
}
响应-2:
{
"ACCTNO": null,
"EXPIRYTIMESTAMP": null,
"LSTCHGTIMESTAMP": null,
"WATCHLSTTYPE": null,
"STATUS": null,
"CHG_TYPE": null,
"REC_TYPE": null,
"lstchgtimestamp": null,
"expirytimestamp": null,
"status": null,
"rec_TYPE": null,
"watchlsttype": null,
"chg_TYPE": null,
"acctno": null
}
类:
import com.fasterxml.jackson.annotation.JsonProperty;
public class InteracAccountAllowList {
@JsonProperty
private String ACCTNO;
@JsonProperty
private String EXPIRYTIMESTAMP;
@JsonProperty
private String LSTCHGTIMESTAMP;
@JsonProperty
private String WATCHLSTTYPE;
@JsonProperty
private String STATUS;
@JsonProperty
private String CHG_TYPE;
@JsonProperty
private String REC_TYPE;
public String getACCTNO() {
return ACCTNO;
}
public void setACCTNO(String aCCTNO) {
ACCTNO = aCCTNO;
}
public String getEXPIRYTIMESTAMP() {
return EXPIRYTIMESTAMP;
}
public void setEXPIRYTIMESTAMP(String eXPIRYTIMESTAMP) {
EXPIRYTIMESTAMP = eXPIRYTIMESTAMP;
}
public String getLSTCHGTIMESTAMP() {
return LSTCHGTIMESTAMP;
}
public void setLSTCHGTIMESTAMP(String lSTCHGTIMESTAMP) {
LSTCHGTIMESTAMP = lSTCHGTIMESTAMP;
}
public String getWATCHLSTTYPE() {
return WATCHLSTTYPE;
}
public void setWATCHLSTTYPE(String wATCHLSTTYPE) {
WATCHLSTTYPE = wATCHLSTTYPE;
}
public String getSTATUS() {
return STATUS;
}
public void setSTATUS(String sTATUS) {
STATUS = sTATUS;
}
public String getCHG_TYPE() {
return CHG_TYPE;
}
public void setCHG_TYPE(String cHG_TYPE) {
CHG_TYPE = cHG_TYPE;
}
public String getREC_TYPE() {
return REC_TYPE;
}
public void setREC_TYPE(String rEC_TYPE) {
REC_TYPE = rEC_TYPE;
}
}
【问题讨论】:
标签: spring spring-boot apache-kafka jackson objectmapper