7

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)
4

1 に答える 1

3

タイプの別の要素を作成してMyBeanList使用する必要があります。JAXBを使用してリストをアンマーシャリング/マーシャリングするSOに関連するもの<String>

于 2010-02-23T01:51:46.527 に答える