java xml转换成list_java-如何使用JAXB将ArrayList转换为XML?

我正在尝试使用JAXB将ArrayList转换为xml.

ArrayList myList = new ArrayList();

myList = retrieveUserAttributes.getUserBasicAttributes(lastName,

retrieveUserAttributes.getLdapContext());

JAXBContext jaxbContext = JAXBContext.newInstance(LDAPUser.class);

Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

StringWriter sw = new StringWriter();

jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

jaxbMarshaller.marshal(myList, sw);

System.out.println(sw.toString());

return sw.toString();

但它不起作用,我收到此错误:

27-Aug-2012 10:43:58 org.apache.catalina.core.StandardWrapperValve

invoke SEVERE: Servlet.service() for servlet [spring] in context with

path [/Spring3-LDAP-WebService] threw exception [Request processing

failed; nested exception is javax.xml.bind.JAXBException: class

java.util.ArrayList nor any of its super class is known to this

context.] with root cause javax.xml.bind.JAXBException: class

java.util.ArrayList nor any of its super class is known to this

context. at

com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:554)

at

com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:470)

at

com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:314)

at

com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:243)

at

javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:96)

at

ie.revenue.spring.RestController.searchLdapUsersByLastNameTwo(RestController.java:69)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)………..

请帮忙!

谢谢.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值