小弟刚接触castor,想测试一下简单的编组/解组,结果测试的时候报出了 ClassDescriptorResolver from context must not be null!{File: [not available]; line: 2; column: 568}错误。
编组生成的xml文件正常,但是把生成的xml数据文件再解组输出的时候就出错了,有大神给指导一下么?谢谢了。
附主要的代码:
Mapping map = new Mapping();
map.loadMapping("allMapping.xml"); File file = new File("testMapping_all.xml");
Writer writer = new FileWriter(file);
Marshaller marshaller = new Marshaller(writer);
marshaller.setMapping(map);
marshaller.marshal(timeTableBean); // now restore the value and list what we get
Reader reader = new FileReader(file);
Unmarshaller unmarshaller = new Unmarshaller(map);
TimeTableBean read = (TimeTableBean)unmarshaller.unmarshal(reader);//这里出错
编组生成的xml文件正常,但是把生成的xml数据文件再解组输出的时候就出错了,有大神给指导一下么?谢谢了。
附主要的代码:
Mapping map = new Mapping();
map.loadMapping("allMapping.xml"); File file = new File("testMapping_all.xml");
Writer writer = new FileWriter(file);
Marshaller marshaller = new Marshaller(writer);
marshaller.setMapping(map);
marshaller.marshal(timeTableBean); // now restore the value and list what we get
Reader reader = new FileReader(file);
Unmarshaller unmarshaller = new Unmarshaller(map);
TimeTableBean read = (TimeTableBean)unmarshaller.unmarshal(reader);//这里出错
<?xml version="1.0" encoding="UTF-8" ?>
- <timetable>
- <carrier identy="BOYIN">
<carrier-name>波音747</carrier-name>
<carrier-type>民航</carrier-type>
</carrier>
- <carrier identy="KONGKE">
<carrier-name>空客A919</carrier-name>
<carrier-type>国航</carrier-type>
</carrier>
- <airport identy="BJ">
<airport-place>首都机场</airport-place>
<airport-name>北京</airport-name>
</airport>
- <airport identy="QD">
<airport-place>流亭机场</airport-place>
<airport-name>青岛</airport-name>
</airport>
- <route from="BJ" to="QD">
<flight carrier="BOYIN" depart="6:23a" arrive="8:42a" number="119" />
<flight carrier="KONGKE" depart="7:23a" arrive="9:42a" number="120" />
</route>
</timetable>
这是在浏览器打开的效果