目前,我正在使用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批注]
发布于 2010-01-12 10:29:43
添加XmlRootElement注释,您将不会再收到错误。这应该添加到顶级或“根”类中。
https://stackoverflow.com/questions/2046289
复制相似问题