这是我的问题,我有一个这样的课A:class A { public A(MyList myList) { this.myList = myList; } @ElementList(name = "MyList", entry = "MyListElement", type = MyListElement.class) private MyList myList; // getters, setters ...}我有我的MyList类,它是一个特定的ArrayList:class MyList extends ArrayList<MyListElement> { public MyList(Long attribute) { this.myListAttribute = attribute; } @Attribute(name = "MyListAttribute") private Long myListAttribute; // getters, setters ...}所以在这里,我的元素列表需要提供一个属性。我发现这是解决方案(扩展ArrayList 类),或者我错了吗?问题在于,一切正常,并按照我想要的方式进行了序列化,即使是包含属性的MyListElement以及除MyList属性之外的许多元素当我尝试序列化时,我得到这样的东西:<A> <MyList> <!-- Here the attribute is missing... --> <MyListElement Att1="X" Att2="Something" Att3="Blabla"> <AnElement>Test</AnElement> <AnotherElement>Test2</AnotherElement> </MyListElement> </MyList></A>我想我错过了文档中的某些内容,也许我做错了什么。提前致谢! 最佳答案 我只是找到了另一种做我想要的方法。也许我做错了,或者框架看起来没有在@ElementList属性上设置的属性。所以我像这样转换了我的MyList类:class MyList { // notice it does not extend ArrayList<MyListElement> anymore // Now I set this list in inline mode @ElementList(entry = "MyListElement", type = MyListElement.class, inline = true) private ArrayList<MyListElement> elementList; @Attribute(name = "MyListAttribute") private Long attribute;}在我的class A中:class A { @Element(name = "MyList") private MyList myList;}这样,我得到了我所期望的:<A> <MyList MyListAttribute="..."> <MyListElement></MyListElement> </MyList></A>关于java - 属性未在自定义ArrayList扩展类上序列化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20372422/
10-11 07:28