2010-02-23 12 views
6

मेरे पास एक MyBean एनोटेटेडश्री बीन के संग्रह में मार्शल/अनमारशाला को जेएक्सबी का उपयोग कैसे करें

@XmlRootElement 
public class MyBean ... 

मार्शलिंग/Unmarshalling MyBean w/o समस्याएं हैं, उदा।

JAXBContext jaxbCtx = JAXBContext.newInstance(MyBean.class); 
Marshaller m = jaxbCtx.createMarshaller(); 
m.marshal(myBean, writer); 

मैं किसी संग्रह या सूची को marshall/unmarshall करने के लिए JAXB का उपयोग कैसे कर सकता हूं?

मेरा प्रयास इस त्रुटि में परिणाम देता है:

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) 

उत्तर

3

आप प्रकार MyBeanList का एक और तत्व बना सकते हैं और इसका इस्तेमाल करने के लिए है। SO Using JAXB to unmarshal/marshal a List<String>

पर कुछ संबंधित