spring在api响应中返回javaobect时添加额外的键

wxclj1h5  于 2021-06-04  发布在  Kafka
关注(0)|答案(1)|浏览(367)

我面临一个问题,spring向我的response对象添加了额外的键。我已附上以下回复(回复-2)。
我还尝试删除@jsonproperty,但也没有用,因为所有键都是小写的。
想要的结果:我希望我所有的键都应该是大写的,就像我在pojo类中声明的那样。我将通过Kafka发送json。
没有@jsonproperty:

{
    "watchlsttype": null,
    "acctno": null,
    "chg_TYPE": null,
    "status": null,
    "rec_TYPE": null,
    "lstchgtimestamp": null,
    "expirytimestamp": null
}

应用程序编程接口:

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

    }
gstyhher

gstyhher1#

答案很简单:在setter方法上使用@jsonproperty(“field\u name”)。

相关问题