/ / कैसे JAXB का उपयोग marshall / unmarshall MyBean का एक संग्रह करने के लिए करें

माईबैन - जावा, संग्रह, जैक्सबी, मार्शलिंग, अनारशेलिंग के संग्रह को मार्शल / अनमारशॉल में जेएक्सबी का उपयोग कैसे करें

मेरे पास एक MyBean एनोटेट है

@XmlRootElement
public class MyBean ...

मार्शलिंग / अनमर्सहॉलिंग माईबीन w / o समस्याएं, उदा।

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

मैं 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 № 1

आपको एक और प्रकार का तत्व बनाना होगा MyBeanList और इसका उपयोग करें। SO पर कुछ संबंधित JAXB का उपयोग सूची / स्ट्रिंग सूची को अनमर्श / मार्शल करने के लिए करें