xstream errors for serializing & deserializing

≯℡__Kan透↙ 提交于 2019-12-05 09:02:48

so the thing that is overlooked here is how you are reading in the file. you are using

XStream xstream = new XStream();
xstream.fromXML("model.xml");

Which is where the period(.) is coming from in the error. The method fromXML is expecting the actual XML input and not the file name. So when it parses your xml (which is "model.xml" not the actual xml) it is giving the error. The site for XStream is down right now so I can't link to the API

Use a FileReader/BufferedReader in order to get the contents of the XML back. Something like this should work

XStream instream = new XStream();

BufferedReader br = new BufferedReader(new FileReader("model.xml"));
StringBuffer buff = new StringBuffer();
String line;
while((line = br.readLine()) != null){
   buff.append(line);
}
Platform p = (Platform)instream.fromXML(buff.toString());

P.S. I was able to duplicate the problem, and fix it with the above

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!