1

我得到了例外

属性或字段规范被注释为瞬态,因此不能包含在proporder注释中。

当尝试为我正在使用的 bean 指定 proporder 时。我没有任何带注释的瞬态,所以我不确定为什么这个异常在运行时会引起它的丑陋。如果我删除了 proporder,我不会得到异常,但是在打印 XML 时,我会丢失“规范”字段并且顺序显然是错误的。

关于我所缺少的任何想法?

这是我正在使用的课程:

端点Bean

@XmlRootElement(name = "endpoint")
@XmlType (propOrder={"specification", "url", "changeset", "type", "formats"})
public class EndpointBean {

    private String specification;
    private String url;
    private String changeset;
    private String type;
    @XmlElementWrapper(name = "formats")
    @XmlElement(name = "format")
    private ArrayList<String> formats;

    public String getSpecification() {
        return specification;
    }

    public void setSpefification(String spefification) {
        this.specification = spefification;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getChangeset() {
        return changeset;
    }

    public void setChangeset(String changeset) {
        this.changeset = changeset;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public ArrayList<String> getFormats() {
        return formats;
    }

    public void setFormats(ArrayList<String> format) {
        this.formats = format;
    }   

}

堆栈跟踪

Exception in thread "main" javax.xml.bind.JAXBException: 
Exception Description: The property or field specification is annotated to be transient so can not be included in the proporder annotation.
 - with linked exception:
[Exception [EclipseLink-50009] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.JAXBException
Exception Description: The property or field specification is annotated to be transient so can not be included in the proporder annotation.]
    at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:1021)
    at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:174)
    at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:165)
    at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:152)
    at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:112)
    at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:102)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.find(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at conversion.Test.main(Test.java:12)
Caused by: Exception [EclipseLink-50009] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.JAXBException
Exception Description: The property or field specification is annotated to be transient so can not be included in the proporder annotation.
    at org.eclipse.persistence.exceptions.JAXBException.transientInProporder(JAXBException.java:229)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.finalizeProperties(AnnotationsProcessor.java:879)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processClassesAndProperties(AnnotationsProcessor.java:282)
    at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:150)
    at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:1017)
    ... 15 more
4

1 回答 1

2

你得到这个异常是因为你有一个 get/set 不匹配。由于在您发布的代码中没有setSpecification方法,因此该属性在内部被视为使用@XmlTransient.

你目前拥有的:

public void setSpefification(String spefification) {
    this.specification = spefification;
}

您需要将 setter 更改为以匹配 getter:

public void setSpecification(String spefification) {
    this.specification = spefification;
}
于 2013-10-03T20:02:49.447 回答