JAXB|MOXy|EclipseLink-java接口com.domain.Entity不能由JAXB映射,因为它有多



所以我遇到了一个问题,我试图将复杂的bean结构转换为XML格式。

我在同一个包中有五个类(带注释)。

每个类扩展一个抽象类并实现一个接口:

@Entity
@Table(name = SubscriptionInvoiceItemChargesImpl.TABLE_NAME)
@DataCache(enabled = false)
public class SubscriptionInvoiceItemChargesImpl extends AbstractEntityImpl implements SubscriptionInvoiceItemCharges {

下面是abstractEntityImpl类:

public abstract class AbstractEntityImpl extends AbstractPersistenceImpl implements Entity {

这是实体接口:

public interface Entity extends PureEntity, Persistence {
}

现在,我只想把我的5个类中定义的方法(通过组合相互依赖)写进XML中,而不想从父类/接口中获得任何数据。

jaxb.properties的内容:

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

这是绑定文件:

<?xml version="1.0"?>
<xml-bindings 
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="com.domain.ecomm.impl">
    <java-types>
        <java-type name="SubscriptionContactImpl" super-type="java.lang.Object"/>
    </java-types>
    <java-types>
        <java-type name="SubscriptionInvoiceItemChargesImpl" super-type="java.lang.Object"/>
    </java-types>
    <java-types>
        <java-type name="SubscriptionInvoiceItemImpl" super-type="java.lang.Object"/>
    </java-types>
    <java-types>
        <java-type name="SubscriptionAccountImpl" super-type="java.lang.Object"/>
    </java-types>
    <java-types>
        <java-type name="SubscriptionImpl" super-type="java.lang.Object"/>
    </java-types>
</xml-bindings>

这是编组代码:

InputStream is = ZuoraServiceImpl.class.getClassLoader().getResourceAsStream("com/domain/ecomm/impl/subscription-bindings.xml");    
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, is);
    JAXBContext jc;
    try {
        jc = JAXBContext.newInstance(new Class[] {SubscriptionContactImpl.class}, properties);
         Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(subscriptionContact, System.out);    
    } catch (JAXBException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

运行代码会给我以下错误:

Exception Description: The java interface com.domain.Entity can not be mapped by JAXB as it has multiple mappable parent interfaces. Multiple inheritence is not supported]

使用的maven依赖项:

<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.5.2</version>
</dependency>

"Entity"接口与其他类位于不同的包中。如果有任何建议,我们将不胜感激。

eclipselink解析器中有一个错误,作为一个解决方案,使用了jaxb.properties和内容

javax.xml.bind.context.factory=com.sun.xml.internal.bind.v2.ContextFactory

jaxb.properties必须与正在序列化的类在同一个包中的类路径中

另一个解决方案是使用eclipselinkjaxb实现

的版本2.6.0

最新更新