1
매우 호기심이 많은 상황이 있습니다.속성 컬렉션에만있는 @XmlElement는 xsi : nil을 인쇄하지 않습니다.
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>
질문 1 : 그 children
에는 xsi:nil
속성이없는 이유는 무엇입니까?