目前我正在使用 Castor 框架将对象编组为 xml 文件,它工作得很好
Writer writer = new FileWriter("D:/out.xml");
Marshaller.marshal(test, writer);
但现在我正在使用 javax.xml.bind 来做同样的事情。
Writer writer = new FileWriter("D:/out.xml");
JAXBContext context =
JAXBContext.newInstance(test.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(test, writer);
然后我遇到了这个错误信息:
无法将类型“package1.Testing”编组为元素,因为它缺少 @XmlRootElement 注释]