Tags

, ,


@XmlRootElement annotation is needed for a class on which we want to do the marshalling.
Else it would throw you a javax.xml.bin.MarshlException, saying unable to marshal type 
"MyClass" as an element because it is missing an @XmlRootElement annotation.

e.g.
        MyClass mine = new MyClass();

        JAXBContext ctx = JAXBContext.newInstance(MyClass.class);
        Marshaller ms = ctx.createMarshaller();
        ms.marshal(mine, System.out);

Advertisements