You can use an @XmlAnyElement
-annotated property and return the elements as JAXBElement
s:
private Map<String, Integer> months = ...;
@XmlAnyElement
public List<JAXBElement<Integer>> getMonths() {
List<JAXBElement<Integer>> elements = new ArrayList<JAXBElement<Integer>>();
for (Map.Entry<String, Integer> month: months.entrySet())
elements.add(new JAXBElement(new QName(month.getKey()),
Integer.class, month.getValue()));
return elements;
}
This approach is ugly, but not uglier than the XML it produces.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…