com.thoughtworks.xstream.converters.ConversionException
使用webService调用接口,返回的是xml格式,运用xstream解析的时候,出现了如下的错误:
1 Exception in thread "Timer-1" com.thoughtworks.xstream.converters.ConversionException: For input string: "VS" : For input string: "VS" 2 ---- Debugging information ---- 3 message : For input string: "VS" 4 cause-exception : java.lang.NumberFormatException 5 cause-message : For input string: "VS" 6 class : java.lang.Integer 7 required-type : java.lang.Integer 8 converter-type : com.thoughtworks.xstream.converters.SingleValueConverterWrapper 9 wrapped-converter : com.thoughtworks.xstream.converters.basic.IntConverter 10 path : /interface/items/roomstate 11 class[1] : catic.hotel.server.webservice.Items 12 converter-type[1] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter 13 class[2] : catic.hotel.server.webservice.Interface 14 version : null 15 ------------------------------- 16 at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79) 17 at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) 18 at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) 19 at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:355) 20 at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:306) 21 at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234) 22 at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) 23 at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) 24 at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) 25 at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) 26 at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:322) 27 at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234) 28 at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) 29 at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) 30 at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) 31 at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) 32 at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134) 33 at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) 34 at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1058) 35 at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1042) 36 at com.thoughtworks.xstream.XStream.fromXML(XStream.java:913) 37 at com.thoughtworks.xstream.XStream.fromXML(XStream.java:904) 38 at catic.library.util.XmlBeanConvertUtil.xml2Bean(XmlBeanConvertUtil.java:27) 39 at catic.library.util.XMLUtil.roomStatusXmlToList2(XMLUtil.java:86) 40 at catic.hotel.server.server.ReadDataByPMSOurDB$ReadPMSUptOurDB.run(ReadDataByPMSOurDB.java:104) 41 at java.util.TimerThread.mainLoop(Unknown Source) 42 at java.util.TimerThread.run(Unknown Source) 43 Caused by: java.lang.NumberFormatException: For input string: "VS" 44 at java.lang.NumberFormatException.forInputString(Unknown Source) 45 at java.lang.Long.parseLong(Unknown Source) 46 at java.lang.Long.valueOf(Unknown Source) 47 at java.lang.Long.decode(Unknown Source) 48 at com.thoughtworks.xstream.converters.basic.IntConverter.fromString(IntConverter.java:27) 49 at com.thoughtworks.xstream.converters.SingleValueConverterWrapper.fromString(SingleValueConverterWrapper.java:41) 50 at com.thoughtworks.xstream.converters.SingleValueConverterWrapper.unmarshal(SingleValueConverterWrapper.java:49) 51 at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) 52 ... 26 more
由43行可以看出,是类型转换异常,因为返回的类型既有String,又有Integer,而我只用了Integer,忽略了String,所以报错。
刚开始还以为是使用xstream报的错,由于是第一次使用这个东东……不过,xstream这个东东真的很好用。