2

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 实现。请帮助。

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

4

2 回答 2

1

更新

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


问题

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

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);
    }

}
于 2013-07-01T10:38:52.483 回答
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);
}

    }
于 2013-07-03T07:03:26.280 回答