Xml瞬态不起作用jaxb(Moxy)。

时间:2013-07-01 07:26:58

标签: xml jaxb moxy xmltransient

Xml瞬态注释不适用于以下模型 -

@XmlRootElement
public class JdfValidation {
private String name;
private String dataType;
private String errorMessage;
private String javaValidationLogic;
protected String displayName;
private boolean isCustom;
private List<ValidationInputParam> validationInputParams = new ArrayList<ValidationInputParam>();
public IFile container;

public JdfValidation() {

}

public JdfValidation(String name, String displayName, boolean isCustom) {
    this.name = name;
    this.displayName = displayName;
    this.isCustom = isCustom;
}

@XmlTransient
public IFile getContainer() {
    return container;
}

public void setContainer(IFile container) {
    this.container = container;
}

/**
 * @return the validationInputParams
 */
@XmlElement
public List<ValidationInputParam> getValidationInputParams() {
    return validationInputParams;
}

/**
 * @param validationInputParams
 *            the validationInputParams to set
 */
public void setValidationInputParams(
        List<ValidationInputParam> validationInputParams) {
    this.validationInputParams = validationInputParams;
}

@XmlAttribute
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@XmlAttribute
public String getDataType() {
    return dataType;
}

public void setDataType(String dataType) {
    this.dataType = dataType;
}

@XmlAttribute
public String getErrorMessage() {
    return errorMessage;
}

public void setErrorMessage(String errorMessage) {
    this.errorMessage = errorMessage;
}

@XmlElement(name = "logic")
public String getJavaValidationLogic() {
    return javaValidationLogic;
}

public void setJavaValidationLogic(String javaValidationLogic) {
    this.javaValidationLogic = javaValidationLogic;
}

@XmlAttribute
public String getDisplayName() {
    return displayName;
}

public void setDisplayName(String displayName) {
    this.displayName = displayName;
}

@XmlAttribute
public boolean isCustom() {
    return isCustom;
}

public void setCustom(boolean isCustom) {
    this.isCustom = isCustom;
}

}

我也试过@XmlAccessorType(XmlAccessType.NONE)bu仍然是相同的异常,上面的工作与默认的jaxb implementation.Plz,help。

  

引起:异常[EclipseLink-50089](Eclipse Persistence Services - 2.5.0.v20130507-3faac2b):org.eclipse.persistence.exceptions.JAXBException   异常说明:JAXB无法映射java接口org.eclipse.core.resources.IFile,因为它具有多个可映射的父接口。不支持多重继承

2 个答案:

答案 0 :(得分:1)

<强>更新

我们已修复此问题背后的错误(请参阅:http://bugs.eclipse.org/411993)它将在 2013年7月4日开始的EclipseLink 2.5.1和2.6.0流中提供。您可以从以下链接下载每晚构建:


<强>问题

如果类型是具有多个超级接口的接口,则告知MOXy(@XmlTransient)忽略属性时,似乎存在错误。

1超级界面 - 工作

public interface IFile extends IFoo  {

}

超过1个超级界面 - 不起作用

public interface IFile extends IFoo, IBar {

}

您可以使用以下错误来跟踪我们在此问题上的进展。


解决方法

您可以使用MOXy的外部映射文档覆盖IFile的超类型以使您的用例有效(请参阅:http://blog.bdoughan.com/2010/12/extending-jaxb-representing-annotations.html):

oxm.xml

<?xml version="1.0"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="forum17399333">
    <java-types>
        <java-type name="IFile" super-type="java.lang.Object"/>
    </java-types>
</xml-bindings>

演示

import java.util.*;
import javax.xml.bind.JAXBContext;
import org.eclipse.persistence.jaxb.JAXBContextProperties;

public class Demo {

    public static void main(String[] args) throws Exception {
        Map<String, Object> properties = new HashMap<String, Object>(1);
        properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "forum17399333/oxm.xml");
        JAXBContext jc = JAXBContext.newInstance(new Class[] {JdfValidation.class}, properties);
    }

}

答案 1 :(得分:0)

另一项工作可能是 -

@XmlRootElement(name = "Validator")
public class JdfValidation {


private Object container; //Cast this to appropriate type

@Transient
public Object getContainer() {
    return container;
}

public void setContainer(Object container) {
    this.container = container;
}
}

演示 -

public class Demo {

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(JdfValidation.class);

    JdfValidation jdfValidation  = new JdfValidation();
            IFile file=getFile();
            jdfValidation.setContainer(file);
            Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(jdfValidation, System.out);
}

    }