经过结合上网查找,发现只需将对应的Item类前加上对应@XStreamAlias("item")注解就行了,谢谢啦。 [图片]
事件推送群发结果,获取后转换为xml文件时报错,事件推送群发结果,获取HttpServletRequest转换为xml文件时,将HttpServletRequest形式为xml文件的字符串时(String requestXml = MessageUtil.parse2Xml(request);),获取的字符串为: [代码]<[代码][代码]xml[代码][代码]><[代码][代码]ToUserName[代码][代码]>[代码][代码]<![CDATA[gh_4cb8fca54b13]]>[代码][代码]</[代码][代码]ToUserName[代码][代码]><[代码][代码]FromUserName[代码][代码]>[代码][代码]<![CDATA[oV_Tssw9sHOSXx2leMYE1ecHzSKk]]>[代码][代码]</[代码][代码]FromUserName[代码][代码]><[代码][代码]CreateTime[代码][代码]>1571039189</[代码][代码]CreateTime[代码][代码]><[代码][代码]MsgType[代码][代码]>[代码][代码]<![CDATA[event]]>[代码][代码]</[代码][代码]MsgType[代码][代码]><[代码][代码]Event[代码][代码]>[代码][代码]<![CDATA[MASSSENDJOBFINISH]]>[代码][代码]</[代码][代码]Event[代码][代码]><[代码][代码]MsgID[代码][代码]>3147483669</[代码][代码]MsgID[代码][代码]><[代码][代码]Status[代码][代码]>[代码][代码]<![CDATA[send success]]>[代码][代码]</[代码][代码]Status[代码][代码]><[代码][代码]TotalCount[代码][代码]>2</[代码][代码]TotalCount[代码][代码]><[代码][代码]FilterCount[代码][代码]>2</[代码][代码]FilterCount[代码][代码]><[代码][代码]SentCount[代码][代码]>2</[代码][代码]SentCount[代码][代码]><[代码][代码]ErrorCount[代码][代码]>0</[代码][代码]ErrorCount[代码][代码]>[代码][代码]<[代码][代码]CopyrightCheckResult[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]Count[代码][代码]>0</[代码][代码]Count[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]ResultList[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]ResultList[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]CheckState[代码][代码]>1</[代码][代码]CheckState[代码][代码]>[代码][代码]</[代码][代码]CopyrightCheckResult[代码][代码]>[代码][代码]<[代码][代码]ArticleUrlResult[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]Count[代码][代码]>1</[代码][代码]Count[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]ResultList[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]item[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]ArticleIdx[代码][代码]>1</[代码][代码]ArticleIdx[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]ArticleUrl[代码][代码]>[代码][代码]<![CDATA[http://mp.weixin.qq.com/s/RrUoc2JYYfgVpVhF0H1qXQ]]>[代码][代码]</[代码][代码]ArticleUrl[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]item[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]ResultList[代码][代码]>[代码][代码]</[代码][代码]ArticleUrlResult[代码][代码]>[代码][代码]</[代码][代码]xml[代码][代码]>[代码]发现<ArticleUrl> -> <ResultList> -> <item>的item项为小写开头的i,所以在之后将形式为xml的字符串解析为相应对象时出错, [代码]ReqBaseMessage reqBaseMessage = parseWechatMessage(requestXml);[代码] [代码]reqBaseMessage = convertResult(requestXml, ReqEventMessage.[代码][代码]class[代码][代码], ReqBaseMessage.[代码][代码]class[代码][代码]);[代码] [代码]@SuppressWarnings[代码][代码]([代码][代码]"unchecked"[代码][代码])[代码][代码] [代码][代码]private[代码] [代码]<T, V> T convertResult(String result, Class<T> clazz, Class<V> parentClazz) {[代码][代码] [代码][代码]XStream xStream = [代码][代码]new[代码] [代码]XStream();[代码][代码] [代码][代码]xStream.addDefaultImplementation(clazz, parentClazz);[代码][代码] [代码][代码]xStream.autodetectAnnotations([代码][代码]true[代码][代码]);[代码][代码] [代码][代码]xStream.processAnnotations(clazz);[代码][代码] [代码][代码]Object transaction = xStream.fromXML(result);[代码][代码] [代码][代码]return[代码] [代码](T)transaction;[代码][代码] [代码][代码]}[代码][代码] [代码] 对应的类为: [图片] [图片] 错误日志如下: [图片] com.thoughtworks.xstream.converters.ConversionException: item : item ---- Debugging information ---- message : item cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException cause-message : item class : java.util.ArrayList required-type : java.util.ArrayList converter-type : com.thoughtworks.xstream.converters.collections.CollectionConverter path : /xml/ArticleUrlResult/ResultList/item line number : 1 class[1] : com.monster.hswx.utils.pojo.req.ArticleUrlResult converter-type[1] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter class[2] : com.monster.hswx.utils.pojo.req.ReqEventMessage version : null ------------------------------- at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:351) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:302) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:230) at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:351) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:302) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:230) at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134) at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1035) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1019) at com.thoughtworks.xstream.XStream.fromXML(XStream.java:895) at com.thoughtworks.xstream.XStream.fromXML(XStream.java:886) at com.monster.hswx.biz.wechat.impl.WeChatCoreServiceManagerImpl.convertResult(WeChatCoreServiceManagerImpl.java:373) at com.monster.hswx.biz.wechat.impl.WeChatCoreServiceManagerImpl.parseWechatMessage(WeChatCoreServiceManagerImpl.java:273) at com.monster.hswx.biz.wechat.impl.WeChatCoreServiceManagerImpl.handleMessage(WeChatCoreServiceManagerImpl.java:100) at com.monster.hswx.webapp.controller.CheckController.index1(CheckController.java:89) at sun.reflect.GeneratedMethodAccessor146.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488) at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:417) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129) at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at com.monster.hswx.webapp.common.filter.CheckFilter.doFilterInternal(CheckFilter.java:69) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at com.yunrich.monster.web.common.session.support.filter.YunRichSessionRequestFilter.doFilterInternal(YunRichSessionRequestFilter.java:40) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at com.monster.hswx.webapp.common.filter.ByPassOtherFilter.doFilterInternal(ByPassOtherFilter.java:62) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) at java.lang.Thread.run(Thread.java:748) Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: item at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:88) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:79) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:74) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:45) at com.thoughtworks.xstream.core.util.HierarchicalStreams.readClassType(HierarchicalStreams.java:29) at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:70) at com.thoughtworks.xstream.converters.collections.CollectionConverter.addCurrentElementToCollection(CollectionConverter.java:79) at com.thoughtworks.xstream.converters.collections.CollectionConverter.populateCollection(CollectionConverter.java:72) at com.thoughtworks.xstream.converters.collections.CollectionConverter.populateCollection(CollectionConverter.java:66) at com.thoughtworks.xstream.converters.collections.CollectionConverter.unmarshal(CollectionConverter.java:61) at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) ... 88 more 请各位大佬解疑,先谢谢啦
2019-10-16