简体   繁体   中英

Mule JAXB Object to XML Transformer throwing JAXBException

I am using Mule 3.6. I have an object which is annotated with JAXB bindings and I am trying to convert it into XML in Mule. Whenever I try to do so, I get a javax.xml.bind.JAXBException: "com.mj.metal.object" doesn't contain ObjectFactory.class or jaxb.index . My transformer are defined as:

<mulexml:jaxb-context name="JAXB_Context" packageNames="com.mj.metal.object"/>
<mulexml:jaxb-object-to-xml-transformer mimeType="application/xml" jaxbContext-ref="JAXB_Context" doc:name="JAXB Object to XML"/>

This package contains my classes to which the transformation is to be made. One of them is:

@XmlRootElement(name = "REPORT")
@XmlAccessorType(XmlAccessType.FIELD)
public class Report {

    @XmlElement(name = "HEADER")
    private Header header;
    @XmlElementWrapper(name = "ITEMS")
    @XmlElement(name = "ITEM")
    private List<Item> items;

    public Report() {
        super();
        header = new Header();
        items = new ArrayList<Item>();
    }

    public Header getHeader() {
        return header;
    }

    public List<Item> getItems() {
        return items;
    }

    public void setHeader(Header header) {
        this.header = header;
    }

    public void setItems(List<Item> items) {
        this.items = items;
    }

    @Override
    public String toString() {
        return "\nReport [header=" + header + "\nitems=" + items + "]";
    }
}

How do I fix this?

You need to add a jaxb.index file to your classpath so that JAXB is able to know which classes it should map your XML data structures to.

The jaxb.index file is nothing more than a list of the classes on the containing package that have JAXB annotations. Simply typing in their simple names (not their fully classified names is enough).

These links might help you:

http://docs.oracle.com/javase/tutorial/jaxb/intro/customize.html

http://cmaki.blogspot.com/2007/09/annotated-jaxb-classes.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM