我遇到了同样的问题。我设法让它工作的唯一方法是一个非常俗气的黑客 - 将 List 包装在另一个类中。
public class MyWrapper {
@ElementList(name="data")
private List<MyClass> data = new ArrayList<MyClass>();
public MyWrapper(List<MyClass> data) {
this.data = data;
}
public List<MyClass> getData() {
return this.data;
}
public void setData(List<MyClass> data) {
this.data = data;
}
}
然后,而不是
@ElementMap Map<String,List<MyClass>>
...您将拥有:
@ElementMap Map<String,MyWrapper>
In my case, the Map is entirely private to my class (i.e. other classes never get to talk directly to the Map), so the fact that I have this extra layer in here doesn't make much of a difference. The XML that is produced of course, is gross, but again, in my case, it's bearable because there is nothing outside of my class that is consuming it. Wish I had a better solution than this, but at the moment, I'm stumped.