本文介绍了如何使用JAXB来编组/取消编组MyBean的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个MyBean注释
I have a MyBean annotated
@XmlRootElement
public class MyBean ...
编组/取消编组MyBean w / o问题,例如
Marshalling/Unmarshalling MyBean w/o problems, e.g.
JAXBContext jaxbCtx = JAXBContext.newInstance(MyBean.class);
Marshaller m = jaxbCtx.createMarshaller();
m.marshal(myBean, writer);
如何使用JAXB来编组/取消编组集合或列表?
How can I use JAXB to marshall/unmarshall a Collection or List?
我的尝试会导致此错误:
My attempt results in this error:
javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "java.util.ArrayList" as an element because it is missing an @XmlRootElement annotation]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:304)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:230)
推荐答案
c $ c> MyBeanList 并使用它。与SO相关的内容使用JAXB取消/编组列表< String>
You have to create another element of type MyBeanList
and use it. Something related on SO Using JAXB to unmarshal/marshal a List<String>
这篇关于如何使用JAXB来编组/取消编组MyBean的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!