MyBeanに注釈を付けている
@XmlRootElement
public class MyBean ...
MyBeanのマーシャリング/アンマーシャリング(問題なし)
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)
回答:
回答№1の場合は3あなたはタイプの別の要素を作成しなければなりません MyBeanList
そしてそれを使ってください。 SOに関連するもの JAXBを使用してList <String>を非整列化/整列化する