私は非常に興味深い状況にあります。
public class Child {
@XmlAttribute
public String name;
}
@XmlRootElement
public class Parent {
public static void main(final String[] args) throws Exception {
final Parent parent = new Parent();
parent.children = new ArrayList<>();
for (int i = 0; i < 3; i++) {
final Child child = new Child();
child.name = Integer.toString(i);
parent.children.add(child);
}
final JAXBContext context = JAXBContext.newInstance(Parent.class);
final Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(parent, System.out);
}
@XmlElement(name = "child", nillable = true)
public List<Child> children;
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<parent>
<child name="0"/> <!-- xsi:nil expected -->
<child name="1"/>
<child name="2"/>
</parent>
xsi:nil
質問 1:それらに属性がないのはなぜchildren
ですか?