Question

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]

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top