不確定標題是否有意義。 我有我想用JAXB,看起來像這樣編組的對象:編組具有對象字段的對象
@XmlRootElement(name = "subscriptionRequest")
public class RegistrationRequest {
private Long id;
private RegistrationSource registrationSource;
}
的RegistrationSource對象:
public class RegistrationSource {
private Integer id;
private String code;
}
我想創建具有以下佈局的XML:
<subscriptionRequest registrationSource="0002">
...
</subscriptionRequest>
其中registrationSource屬性值是RegistrationSource對象的代碼字段值。
我需要使用哪些xml註釋?
我得到以下異常: 異常線程「main」 com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions 1個計數 @XmlValue不允許在派生另一個類的類。 – Imhotep 2010-01-21 16:12:31
@Imhotep:我添加了工作代碼。 – axtavt 2010-01-21 16:46:29
在你寫下這段代碼之前,我把註釋放在字段聲明中。之後,我看到了你的代碼和應用的變化,我得到這些:在線程「主要」 com.sun.xml.bind.v2.runtime.IllegalAnnotationsException 例外:IllegalAnnotationExceptions的5個計數 @XmlValue不允許在類導出另一類。 。 如果一個類具有@XmlElement屬性,則它不能具有@XmlValue屬性。 。 @ XmlAttribute/@ XmlValue需要引用映射到XML中的文本的Java類型。 。 類有兩個名稱相同的屬性「registrationSource」 。 類有兩個同名「代碼」的屬性 – Imhotep 2010-01-21 17:19:43