开发者

Castor and JAXB Marshaller

开发者 https://www.devze.com 2022-12-15 22:17 出处:网络
Currently I am using Castor framework to marshall the object into xml file it work greats Writer writer = new FileWriter(\"D:/out.xml\"开发者_运维技巧);

Currently I am using Castor framework to marshall the object into xml file it work greats

Writer writer = new FileWriter("D:/out.xml"开发者_运维技巧);
Marshaller.marshal(test, writer);

But now I am using javax.xml.bind to do the same thing.

            Writer writer = new FileWriter("D:/out.xml");
        JAXBContext context =
            JAXBContext.newInstance(test.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.marshal(test, writer);

Then I hits this error message :

unable to marshal type "package1.Testing" as an element because it is missing an @XmlRootElement annotation]


Add the XmlRootElement annotation and you won't get the error anymore. This should be added to the top-level or "root" class.

0

精彩评论

暂无评论...
验证码 换一张
取 消