我有一个 json 对象,其属性名称如下:itemsRequired
, sortable_list
. 在我的 ObjectMapper 中,我有
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
随着这sortable_list
被映射到 POJO 中的适当属性,但itemsRequired
被忽略。而如果我删除PropertyNamingStrategy
, 则itemsRequired
可以,sortable_list
但不能。如果我想让两者一起工作应该怎么做?
我正在使用 fastxml 库。我也尝试过 codehaus 的 jackson,结果相同。
更新:POJO如下,
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public class CreateList extends Header {
private String question;
private String placeholder;
private String help;
private int itemsRequired;
private List<String> list;
// Getter and Setter methods
}
而 JSON 是,
"create": {
"heading": "Activities Available to You",
"question": "List at least four activities at school and in your community that you may want to try out.\n",
"placeholder": "List an activity",
"help": "You can only have 10 list items",
"list": [],
"items_required": 4
}
如果我有上面的 JSON,一切正常。但是当我将 JSON 更改为时,事情不起作用,
"create": {
"heading": "Activities Available to You",
"question": "List at least four activities at school and in your community that you may want to try out.\n",
"placeholder": "List an activity",
"help": "You can only have 10 list items",
"list": [],
"itemsRequired": 4
}
itemsRequired 在后一种情况下被忽略。
我希望它在这两种情况下都能工作,无论它被命名为items_required
还是itemsRequired
.