When you are trying marshal MyClass, that is not anotated as @XmlRootElement element, you can obtain:
unable to marshal type "org.company.MyClass" as an element because it is missing an @XmlRootElement annotation
Possible workaround is marshal your object in this way:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Marshaller marshaller = jc.createMarshaller(); | |
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); | |
marshaller.marshal(new JAXBElement<MyClass>(new QName("NameSpaceUri","ElementName"), MyClass.class, myClassInstance), System.out); |
I have found, that more details can be found here:
http://weblogs.java.net/blog/2006/03/03/why-does-jaxb-put-xmlrootelement-sometimes-not-always
http://stackoverflow.com/questions/819720/no-xmlrootelement-generated-by-jaxb
Žádné komentáře:
Okomentovat