当前位置: 首页 > news >正文

泰安做网站的公司神起网络游戏推广平台

泰安做网站的公司,神起网络游戏推广平台,榆林市工程造价信息网,电商网站的支付模块怎么做很多老系统,特别是C的系统,可能数据结构采用的xml。xml对java来说没有什么,但是C来说,可能还有个顺序问题,毕竟c没有那么多通用类库。 2 xstream 先说依赖,我本来不想升级,但是有个问题卡者就给…

很多老系统,特别是C++的系统,可能数据结构采用的xml。xml对java来说没有什么,但是C++来说,可能还有个顺序问题,毕竟c++没有那么多通用类库。
2 xstream
先说依赖,我本来不想升级,但是有个问题卡者就给升了,虽然升了并没有解决我的问题。

     <!-- xstream 升级到1.4.18后 依赖的jar --><dependency><groupId>com.thoughtworks.xstream</groupId><artifactId>xstream</artifactId><version>1.4.20</version></dependency><dependency><groupId>xmlpull</groupId><artifactId>xmlpull</artifactId><version>1.1.3.4d_b4_min</version></dependency><dependency><groupId>xpp3</groupId><artifactId>xpp3_min</artifactId><version>1.1.4c</version></dependency>

2.1 双下划线问题
看下面注释

    public static String toXml(Object obj) {
//        XStream xstream = new XStream(new DomDriver(encoding));XStream xstream = new XStream(new Xpp3Driver(new NoNameCoder())); // 解决xml双下划线的问题//            XStream xstream=new XStream(new DomDriver()); //直接用jaxp dom来解释//            XStream xstream=new XStream(new DomDriver("utf-8")); //指定编码解析器,直接用jaxp dom来解释//如果没有这句,xml中的根元素会是<包.类名>;或者说:注解根本就没生效,所以的元素名就是类的属性xstream.processAnnotations(obj.getClass()); //通过注解方式的,一定要有这句话return xstream.toXML(obj);}

2.2 复杂对象转换的问题
一般的复杂结构还不会有问题,但是老式的默认却不行,很奇怪。

com.thoughtworks.xstream.converters.ConversionException: 
---- Debugging information ----
cause-exception     : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message       : COMMON_FPKJ_XMXX
class               : com.whty.einv.sks.model.params.req.body.ReqInvoiceIssueBody026Bean
required-type       : com.whty.einv.sks.model.params.req.body.ReqInvoiceIssueBody026Bean
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /business/REQUEST_COMMON_FPKJ/COMMON_FPKJ_XMXXS
line number         : 32
class[1]            : com.whty.einv.sks.model.params.req.business.ReqInvoiceIssue026Bean
required-type[1]    : com.whty.einv.sks.model.params.req.business.ReqInvoiceIssue026Bean
version             : 1.4.20
-------------------------------at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:81)at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72)at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:68)at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:499)at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:425)at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:277)at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:74)at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72)at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:68)at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:52)at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:136)at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1464)at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1441)at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1321)at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1312)at com.whty.einv.sks.model.util.XmlUtil.toBean(XmlUtil.java:53)at com.whty.einv.sks.model.test.TestJavaToXml.toBean(TestJavaToXml.java:108)at com.whty.einv.sks.model.test.TestJavaToXml.test10_026(TestJavaToXml.java:86)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: COMMON_FPKJ_XMXXat com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:81)at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55)at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)at com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:88)at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:79)at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:74)at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)at com.thoughtworks.xstream.mapper.SecurityMapper.realClass(SecurityMapper.java:71)at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:47)at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:420)at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:277)at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:74)... 40 moreProcess finished with exit code -1

.1 jibx实现
先看依赖,使用这个技术比较麻烦一点,就是再打包的时候要执行mvn jibx:bind

  <dependency><groupId>org.jibx</groupId><artifactId>jibx-run</artifactId><version>1.3.1</version></dependency><dependency><groupId>org.jibx</groupId><artifactId>jibx-extras</artifactId><version>1.3.1</version><scope>test</scope></dependency><dependency><groupId>org.jibx</groupId><artifactId>jibx-tools</artifactId><version>1.3.1</version><scope>test</scope></dependency>

再看打包

<build><plugins><!-- 源码插件 --><plugin><artifactId>maven-source-plugin</artifactId><version>2.1</version><configuration><attach>true</attach></configuration><executions><execution><phase>compile</phase><goals><goal>jar</goal></goals></execution></executions></plugin><plugin><groupId>org.jibx</groupId><artifactId>jibx-maven-plugin</artifactId><version>1.3.1</version><configuration><schemaBindingDirectory>src/main/resources</schemaBindingDirectory><includeSchemaBindings><!-- 每次执行前需要先mvn clean compile test-compile或手动删除Jibx生成的文件,再执行mvn jibx:bind,有相同类名时,一次性会执行失败  --><!-- jibx生成的所有类文件会位于第一个生成的类的同目录下,分开执行可以在不同的文件夹生成对应类 --><includeSchemaBindings>binding/request/*-binding.xml</includeSchemaBindings><includeSchemaBindings>binding/response/*-binding.xml</includeSchemaBindings></includeSchemaBindings><verbose>true</verbose></configuration><executions><execution><goals><goal>bind</goal></goals></execution></executions></plugin></plugins><resources><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources></build>

使用如下

	/*** obj转xml** @param obj* @param indent 格式化缩进* @return String* @throws JiBXException*/public static String toXml(Object obj, int indent) throws JiBXException {IBindingFactory bfact = BindingDirectory.getFactory(obj.getClass());IMarshallingContext mctx = bfact.createMarshallingContext();mctx.setIndent(indent);StringWriter writer = new StringWriter();mctx.marshalDocument(obj, encoding, null, writer);return writer.toString();}/*** xml转obj** @param xml* @param clazz* @return* @throws JiBXException*/public static <T> T fromXml(String xml, Class<T> clazz) throws JiBXException {IBindingFactory bfact = BindingDirectory.getFactory(clazz);IUnmarshallingContext uctx = bfact.createUnmarshallingContext();Object obj = uctx.unmarshalDocument(new StringReader(xml), null);return clazz.cast(obj);}
http://www.laogonggong.com/news/46106.html

相关文章:

  • 中国建设银行门户网站长春seo关键词排名
  • 网站免费软件下载ip反查域名网站
  • 怎么制作自己的网页网站中国最新军事新闻最新消息
  • 建设服务型政府网站好看的网站模板
  • 厦门做网站多站长统计app软件下载官网安卓
  • 网站制作一条龙seo公司的选上海百首网络
  • 仿制别人的网站违法吗seo就业哪家好
  • 做网站销售有前景吗建设网站制作
  • 合肥网站建设开发电话长尾词挖掘免费工具
  • dw创建网站导航栏菜单怎么做百度sem竞价推广电子书
  • 微网站 微信百度关键词搜索指数
  • wordpress 压缩包seo系统源码
  • 大学生个体创业的网站建设app营销策略有哪些
  • 怎样在网站做友情链接重庆网络seo公司
  • html5网站开发的源码客源引流推广
  • 湛江高端网站开发免费加客源软件
  • 做卖车的网站有哪些如何把一个关键词优化到首页
  • 杭州哪家做外贸网站seo排名系统
  • 网站降权该怎么做软文代写自助发稿平台
  • 重庆做企业网站百度怎么做网站
  • 怎样给网站做排名优化杭州seo网站
  • wordpress安装失败无法创建目录seo快速优化排名
  • 奢侈品网站建设方案广告投放渠道
  • 建网站需要多长时间深圳全网推广方案
  • 甘肃seo网站品牌策划方案ppt
  • 网站建设未来发展前景seogw
  • 新网个人网站备案站长之家ppt模板
  • 乌鲁木齐可以做网站的公司有哪些优化防疫政策
  • 西宁做网站西安做网页的公司
  • 如何做网站流量短视频营销