我创建了以下类以将 a 映射Map<String, DynamicTarget>
到 a DynamicTarget[]
:
class DynamicTargetMapAdapter extends XmlAdapter<DynamicTarget[], Map<String, DynamicTarget>> {
public DynamicTarget[] marshal(Map<String, DynamicTarget> arg0) throws Exception {
DynamicTarget[] mapElements = new DynamicTarget[arg0.size()];
int i = 0;
for (DynamicTarget d : arg0.values()) mapElements[i++] = d;
return mapElements;
}
public Map<String, DynamicTarget> unmarshal(DynamicTarget[] arg0) throws Exception {
Map<String, DynamicTarget> r = new HashMap<String, DynamicTarget>();
for (DynamicTarget d : arg0) r.put(d.getName(), d);
return r;
}
}
结果是这样的:
<dynamicTargets>
<item>
...
</item>
<item>
...
</item>
<item>
...
</item>
</dynamicTargets>
但这就是我想要实现的目标:
<dynamicTargets>
<target>
...
</target>
<target>
...
</target>
<target>
...
</target>
</dynamicTargets>
我需要做什么才能获得所需的输出?