杰克逊JSON字段映射大写? [英] Jackson JSON field mapping capitalization?

查看:153
本文介绍了杰克逊JSON字段映射大写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不清楚杰克逊如何处理绘图领域的资本化。如果有人可以提供帮助,我会很感激。

I'm not clear how jackson deals with capitalization in mapping fields. If anyone could help I'd appreciate it.

{"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,下面是我的例外......

Above is my json, below is my exception...

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"])

以上是我的例外,下面是我的班级...

Above is my exception, below is my class...

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

...等等

推荐答案

由于您的setter方法名为 setMDReqID(...) Jackson假定该变量由于Java命名约定而被命名为mDReqID (变量应以小写字母开头)。如果你真的想要一个大写字母,请使用 setter上的@JsonProperty 注释(或 - 用于序列化 - 在getter上),如下所示: @JsonProperty(MDReqID)

Since your setter method is named setMDReqID(…) Jackson assumes the variable is named mDReqID because of the Java naming conventions (variables should start with lower case letters). If you really want a capital letter use the @JsonProperty annotation on the setter (or - for serialization - on the getter) like this: @JsonProperty("MDReqID").

这篇关于杰克逊JSON字段映射大写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆