Java / JAXB: ungroup XML elements with the same name but different attribute values into different class members
•
Java
I try to parse XML with multiple "fields" elements into different class members according to one of the attributes
<Series>
<Fields type="SelectedFields" operation="SUM">
<Field name="Remaining" />
<Field name="Invested" />
</Field>
<Fields type="FirstSelectedFields" operation="SUM">
<Field name="Estimated" />
</Field>
</Series>
This is the Java class that should be mapped to:
public class APMSeries {
private List<Field> selectedFields;
private List<Field> firstSelectedFields;
}
Who can tell me how to set a fields element with attribute type = "selectedfields" as a selectedfields member and a fields element with attribute type = "firstselectedfields" as a firstselectedfields member?
Solution
public class APMSeries {
public class APMSeries {
@XmlElementWrapper(name="SelectedFields")
private List<Field> selectedFields;
@XmlElementWrapper(name="FirstSelectedFields")
private List<Field> firstSelectedFields;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
