可能吗:
Class Qwe {
@SuperAdapter
Map<String, String> prms
}
编组后:
<qwe>
<prms>
<prm>
<name>qwe</name>
<val>zxc</val>
</prm>
<prm>
<name>tyu</name>
<val>ghj</val>
</prm>
...
</prms>
</qwe>
如果我可以访问DOM或插入ram xml部分,则可以解决此问题。
或建议我最好的解决方案。
我可以通过子类解决它,但是我认为这不是一个好的解决方案。
最佳答案
请参阅Blaise Doughan的this post。片段:
package blog.map;
import java.util.*;
import javax.xml.bind.annotation.*;
@XmlRootElement
public class Customer {
private Map<String, Address> addressMap = new HashMap<String, Address>();
@XmlElementWrapper(name="addresses")
public Map<String, Address> getAddressMap() {
return addressMap;
}
public void setAddressMap(Map<String, Address> addressMap) {
this.addressMap = addressMap;
}
}
输出:
<?xml version="1.0" encoding="UTF-8"?>
<customer>
<addresses>
<entry>
<key>shipping</key>
<value>
<street>2 B Road</street>
</value>
</entry>
<entry>
<key>billing</key>
<value>
<street>1 A Street</street>
</value>
</entry>
</addresses>
</customer>