我一直在試圖將自我創建的xml配置文件解組爲一個JAXB默認實現的對象,我忽略了原因,但是一些內部元素和值被略過給我空結果。JAXB忽略內部元素
這裏是XML文檔:
<import-sources>
<domain-objects>
<domain-object class="xxx.xxx.core.business.mapping.Make">
<sources>
<source name="xxxxxx" class="xxx.xxx.core.web.common.model.xxxxxxx.output.MakeDTO">
<uri secured="true" value="xxxxxxxxxxxxxxxxxx"/>
<key name="api_key" mode="in_uri" value="xxxxxxxxxxxx"/>
</source>
</sources>
</domain-object>
</domain-objects>
這是映射類:
@XmlRootElement(name = "import-sources")
public class ImportSources {
@XmlType
public static class DomainObject {
@XmlType
public static class Source {
@XmlType
public static class URI {
private String value;
private boolean secured;
}
@XmlType
public static class Key {
@XmlEnum
public enum Mode {
@XmlEnumValue("in_uri")
IN_URI,
@XmlEnumValue("in_header")
IN_HEADER
}
private String name;
private String value;
private Mode mode;
}
private String name;
private URI uri;
private Key key;
@XmlElement(name = "class")
private Class outputClass;
}
@XmlAttribute(name = "class")
private Class<? extends Entity> subjectClass;
@XmlElementWrapper
@XmlElement(name = "source")
private Source[] sources;
}
@XmlElementWrapper(name = "domain-objects")
@XmlElement(name = "domain-object")
private DomainObject[] domainObjects;
}
解析與Unmarshaller.unmarshall文檔()所有源的字段爲空後,如果我替換它的內部標籤屬性,我可以得到它的標量字段:
<source>
<name>....</name>
<class>...</class>
</source>
我想避免這種冗餘。