I want to generate list tag and object tag in jaxb. I have two classes.
我想在jaxb中生成列表标记和对象标记。我有两类。
@XmlRootElement(name = "firstclass")
class Firstclass{
List<secondclass> secondclassList = new ArrayList<secondclass>();
//constructors, getters, setters
@XmlElement(name = "secondclassList")
public void setsecondclassList(List<Secondclass> secondclassList) {
this.secondclassList= secondclassList;
}
}
second class code
第二个类的代码
@XmlRootElement(name = "secondclass")
class Secondclass{
String name;
String attribute;
//constructors, getters, setters
}
After xml conversion, I am getting output like
在xml转换之后,我将得到类似的输出
<firstclass>
<secondclassList>
<name>my name</name>
<attribute>attr value 11</attribute>
<secondclassList>
</secondclassList>
<name>my name</name>
<attribute>attr value 22</attribute>
</secondclassList>
</firstclass>
but I want output like this
但我想要这样的输出
<firstclass>
<secondclassList>
<secondclass>
<name>my name</name>
<attribute>attr value 11</attribute>
</secondclass>
<secondclass>
<name>my name</name>
<attribute>attr value 22</attribute>
</secondclass>
</secondclassList>
</firstclass>
1 个解决方案
#1
4
Try using:
尝试使用:
@XmlElementWrapper(name = "secondclassList")
@XmlElement(name="secondclass")
public void setsecondclassList(List<Secondclass> secondclassList) {
#1
4
Try using:
尝试使用:
@XmlElementWrapper(name = "secondclassList")
@XmlElement(name="secondclass")
public void setsecondclassList(List<Secondclass> secondclassList) {