Jackson JSON字段映射大写吗?

我不清楚杰克逊如何处理映射字段中的大写字母。如果有人可以帮忙,我将不胜感激。

{"user":{"username":"user@host.com","password":"pwd","sendercompid":"COMPID","service":{"host":"address","port":6666,"service":"S1","serviceAsString":"s1"}},"MDReqID":"ghost30022","NoRelatedSym":1,"Symbol":["GOOG"],"MarketDepth":"0","NoMDEntryTypes":3,"MDEntryType":["0","1","2"],"SubscriptionRequestType":"1","AggregatedBook":"N"}:

上面是我的json,下面是我的例外…

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "MDReqID" (class com.myco.qa.fixrest.MarketDataRequest), not marked as ignorable (10 known properties: , "mdreqID", "marketDepth", "user", "subscriptionRequestType", "aggregatedBook", "mdentryType", "symbol", "mdupdateType", "noRelatedSym", "noMDEntryTypes"])

上面是我的例外,下面是我的课…

public class MarketDataRequest {

private User user;

private String MDReqID;

private char SubscriptionRequestType;

private int MarketDepth;

private int MDUpdateType;

private char AggregatedBook;

private int NoMDEntryTypes;

private ArrayList<Character> MDEntryType;

private int NoRelatedSym;

private ArrayList<String> Symbol;

public User getUser() {

return user;

}

public void setUser(User user) {

this.user = user;

}

public String getMDReqID() {

return MDReqID;

}

public void setMDReqID(String MDReqID) {

this.MDReqID = MDReqID;

}

public char getSubscriptionRequestType() {

return SubscriptionRequestType;

}

public void setSubscriptionRequestType(char subscriptionRequestType) {

SubscriptionRequestType = subscriptionRequestType;

}

…等等

回答:

由于您的设置方法命名为setMDReqID(…)Jackson,因此假设变量的命名mDReqID是基于Java的 命名约定

(变量应以小写字母开头)。

如果您真的想要一个大写字母,请使用 setter 上的

@JsonProperty

注释(或-进行序列化-在 getter上 ),如下所示:

@JsonProperty("MDReqID")

public void setMDReqID(String MDReqID) {

this.MDReqID = MDReqID;

}

以上是 Jackson JSON字段映射大写吗? 的全部内容, 来源链接: utcz.com/qa/399317.html

回到顶部