我的课程结构如下:
@XmlRootElement(name="rootClass")
@XmlAccessorType(XmlAccessType.FIELD)
public class rootClass {
@XmlElementWrapper(name="children")
@XmlElement(name="child", type=childClass.class)
private List<childClass> children;
// Constructor, Getters, Setters
}
public class childClass {
private String name;
}
如果实例绑定到 xml,它看起来像这样,完全符合预期:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rootClass>
<children>
<child>
<name>Peter</name>
</child>
<child>
<name>Griffin</name>
</child>
</children>
</rootClass>
但在 JSON 中,它看起来像这样:
{
"children": {
"child": [
{
"name": "Peter"
},
{
"name": "Griffin"
}
]
}
}
虽然我希望它看起来像这样:
{
"children": [
{
"name": "Peter"
},
{
"name": "Griffin"
}
]
}
这种行为是由错误的注释引起的还是由于缺少注释参数的结果?