Reputation: 5469
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?
Upvotes: 0
Views: 2043
Reputation: 734
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
Upvotes: 2