开发者

Castor and JAXB Marshaller

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜