使用webService调用接口,返回的是xml格式,运用xstream解析的时候,出现了如下的错误:
Exception in thread "Timer-1" com.thoughtworks.xstream.converters.ConversionException: For input string: "VS" : For input string: "VS"
---- Debugging information ----
message : For input string: "VS"
cause-exception : java.lang.NumberFormatException
cause-message : For input string: "VS"
class : java.lang.Integer
required-type : java.lang.Integer
converter-type : com.thoughtworks.xstream.converters.SingleValueConverterWrapper
wrapped-converter : com.thoughtworks.xstream.converters.basic.IntConverter
path : /interface/items/roomstate
class[1] : catic.hotel.server.webservice.Items
converter-type[1] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
class[2] : catic.hotel.server.webservice.Interface
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:355)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:306)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
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.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:322)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
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:1058)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1042)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:913)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:904)
at catic.library.util.XmlBeanConvertUtil.xml2Bean(XmlBeanConvertUtil.java:27)
at catic.library.util.XMLUtil.roomStatusXmlToList2(XMLUtil.java:86)
at catic.hotel.server.server.ReadDataByPMSOurDB$ReadPMSUptOurDB.run(ReadDataByPMSOurDB.java:104)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Caused by: java.lang.NumberFormatException: For input string: "VS"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.valueOf(Unknown Source)
at java.lang.Long.decode(Unknown Source)
at com.thoughtworks.xstream.converters.basic.IntConverter.fromString(IntConverter.java:27)
at com.thoughtworks.xstream.converters.SingleValueConverterWrapper.fromString(SingleValueConverterWrapper.java:41)
at com.thoughtworks.xstream.converters.SingleValueConverterWrapper.unmarshal(SingleValueConverterWrapper.java:49)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
... 26 more
由43行可以看出,是类型转换异常,因为返回的类型既有String,又有Integer,而我只用了Integer,忽略了String,所以报错。
刚开始还以为是使用xstream报的错,由于是第一次使用这个东东……不过,xstream这个东东真的很好用。