本文介绍了Mule JAXB对象到XML Transformer抛出JAXBException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mule 3.6。我有一个用JAXB绑定注释的对象,我试图将它转换为Mule中的XML。每当我尝试这样做时,我得到一个 javax.xml.bind.JAXBException:com.mj.metal.object不包含ObjectFactory.class或jaxb.in​​dex 。我的变换器定义为:

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 + "]";
    }
}

如何解决此问题?

推荐答案

您需要在类路径中添加一个jaxb.in​​dex文件,以便JAXB能够知道它应该将XML数据结构映射到哪些类。

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.

jaxb.in​​dex文件只不过是包含JAXB注释的包含类的列表。只需输入简单的名称(不是完全分类的名称就足够了)。

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:

这篇关于Mule JAXB对象到XML Transformer抛出JAXBException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:21