I have a class to store a list of SWT widgets.
@XmlRootElement
class Test {
private List<Widget> widgets;
public List<Widget> getWidgets() {
return widgets;
}
public void setWidgets(List<Widget> widgets) {
this.widgets = widgets;
}
}
I used JAXB to marshall it into XML. However, these widgets are not marshalled.
Test t = new Test();
t.setWidgets(widgets);
JAXBContext context = JAXBContext.newInstance(Test.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(t, System.out);
This is the output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<test>
<widgets/>
<widgets/>
<widgets/>
</test>
Your JAXB (JSR-222) implementation can’t determine the subclasses of
Widgetusing reflection, so you will need to include them when you create your JAXBContext.