試圖將我的類映射到xml並添加自定義屬性。jaxb xmlelement使用自定義屬性編組
public class MyXmlMappings {
@XmlElement
protected String username;
@XmlElement
protected String password;
@XmlElement
protected Integer age;
}
編組爲XML後看起來是這樣的:
<myXmlMappings>
<username/>
<password/>
<age/>
</myXmlMappings>
我需要有這樣的XML:
<myXmlMappings>
<username type="String" defaultValue="hello" />
<password type="String" defaultValue="asdf" />
<age type="Integer" defaultValue="25" />
</myXmlMappings>
正如你可以看到我添加的類型和默認值的屬性。如何將它們添加到myXmlMappings類中以便在編組後可見?
向myXmlMappings類添加額外的字段是不可行的我想以某種方式做註釋。
哪裏的默認值從何而來? – 2012-08-01 16:04:38