Java jaxb删除列表标记
我需要整理一个java类来获得xml,但我不知道如何删除生成的类中的标记 我有一个类,它有一个对象列表Java jaxb删除列表标记,java,xml,jaxb,marshalling,Java,Xml,Jaxb,Marshalling,我需要整理一个java类来获得xml,但我不知道如何删除生成的类中的标记 我有一个类,它有一个对象列表 @XmlRootElement(name = "Element") public class Element { private List<Foo> foos; @XmlElementWrapper("fooList") public List<Foo> getfoos() { return foos; } pub
@XmlRootElement(name = "Element")
public class Element {
private List<Foo> foos;
@XmlElementWrapper("fooList")
public List<Foo> getfoos() {
return foos;
}
public void setFoos(List<Foo> foos) {
this.foos = foos;
}
}
当编组以获取xml时,我得到以下结果:
<Element>
<fooList>
<foos>
<string1>asd</string1>
<string2>qwe</string2>
</foos>
<foos>
<string1>poi</string1>
<string2>lkj</string2>
</foos>
</fooList>
</Element>
自闭症
qwe
poi
列车运行监控装置
但是我想在没有标签的情况下得到它,就像这样:
<Element>
<fooList>
<string1>asd</string1>
<string2>qwe</string2>
<string1>poi</string1>
<string2>lkj</string2>
</fooList>
</Element>
@XmlRootElement(name = "Element")
@XmlAccessorType(XmlAccessType.FIELD)
public class Element {
@XmlElementWrapper(name = "fooList")
@XmlElements({
@XmlElement(name = "id", type = Id.class),
@XmlElement(name = "code", type = Code.class),
})
private List<FooItem> foos;
public List<FooItem> getfoos() {
return foos;
}
public void setFoos(List<FooItem> foos) {
this.foos = foos;
}
}
自闭症
qwe
poi
列车运行监控装置
有人能帮我吗?
非常感谢 您可以这样做:
<Element>
<fooList>
<string1>asd</string1>
<string2>qwe</string2>
<string1>poi</string1>
<string2>lkj</string2>
</fooList>
</Element>
@XmlRootElement(name = "Element")
@XmlAccessorType(XmlAccessType.FIELD)
public class Element {
@XmlElementWrapper(name = "fooList")
@XmlElements({
@XmlElement(name = "id", type = Id.class),
@XmlElement(name = "code", type = Code.class),
})
private List<FooItem> foos;
public List<FooItem> getfoos() {
return foos;
}
public void setFoos(List<FooItem> foos) {
this.foos = foos;
}
}
它们由一个没有多大作用的接口所限定:
public interface FooItem { }
此结构将允许您按指定的格式封送到xml中
类结构的挑战在于,类Foo有2个字段,@XmlValue只能应用于每个类的一个字段。因此,有两个字段“强制”它们代表@XmlElement,而它们又必须是xml元素的子元素。这就是为什么在xml中为列表中的每个foo实例使用“中间”foo元素的原因。这些类是为您生成的吗?你能改变他们的结构吗?你愿意吗?是的,这些类是由我生成的,我可以更改它们。谢谢@mart,它解决了我的问题,我现在得到了其他类,但我正在解决它们。@RodrigoArnaizPiorno别担心!如果你在其他问题上需要任何帮助,我很乐意帮助你