Json 奇怪的映射行为

Json 奇怪的映射行为,json,jackson,Json,Jackson,我对Android上的Jackson有一个奇怪的映射问题 我有一个内容类,应该由Jackson Mapper使用 看起来是这样的: public class content { private String header; private String subheader; private String bodytext; @JsonProperty("singleimage") private String image; @JsonPropert

我对Android上的Jackson有一个奇怪的映射问题

我有一个内容类,应该由Jackson Mapper使用

看起来是这样的:

public class content {
    private String header;
    private String subheader;
    private String bodytext;
    @JsonProperty("singleimage")
    private String image;
    @JsonProperty("uid")
    private String id;
    @JsonProperty("link")
    private String article;
    @JsonProperty("CType")
    private String cType;

    // Eclipse auto generated getters & setters
    ...
}
{
    "header": "xyz",
    "subheader": "abc",
    "bodytext": "abc",
    "singleimage": "abc",
    "images": "abc.jpg",
    "teaser_elements": "",
    "uid": "13",
    "link": "xyz.htm",
    "CType": "row_header"
}
对应的JSON对象如下所示:

public class content {
    private String header;
    private String subheader;
    private String bodytext;
    @JsonProperty("singleimage")
    private String image;
    @JsonProperty("uid")
    private String id;
    @JsonProperty("link")
    private String article;
    @JsonProperty("CType")
    private String cType;

    // Eclipse auto generated getters & setters
    ...
}
{
    "header": "xyz",
    "subheader": "abc",
    "bodytext": "abc",
    "singleimage": "abc",
    "images": "abc.jpg",
    "teaser_elements": "",
    "uid": "13",
    "link": "xyz.htm",
    "CType": "row_header"
}
现在,当我使用Jackson映射器从提供的JSON创建内容实例时,内容类的所有字段都得到了正确填充—除了cType之外的所有字段

我已经尝试将@JSONPropertyType注释移动到setCType方法,但仍然没有效果

在映射类或其他任何东西时,我没有得到任何异常,在我看来,所有映射几乎都对字符串进行相同的映射,我有点困惑,为什么它不能与CType一起工作


非常感谢您对问题的任何建议。

哪种Jackson版本?我目前使用的版本是2.1.4好的,我最终找到了问题的解决方案-它与transformer类中引入的命名策略有关。它被设置为带有下划线的CAMEL_CASE_to_LOWER_CASE_,所以我在我的内容类中添加了@JsonNamingCustomNamingStrategy.classe。CustomNamingStrategy处理响应中返回的所有异常命名转换。