当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Changing a MapAdapters default element output name with JAXB

问题描述:

I created the following class to map a Map<String, DynamicTarget> to 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;

}

}

The result is this:

<dynamicTargets>

<item>

...

</item>

<item>

...

</item>

<item>

...

</item>

</dynamicTargets>

But this is what I want to achieve:

<dynamicTargets>

<target>

...

</target>

<target>

...

</target>

<target>

...

</target>

</dynamicTargets>

What do i need to do to get the desired output?

分享给朋友:
您可能感兴趣的文章:
随机阅读: