以上XML具有嵌套的ArrayList结构
我写了一段代码
{ XStream xstream = new XStream();
xstream.processAnnotations(Travels.class);
String xml = xstream.toXML(t);
System.out.println(xml);
xstream.registerConverter(new HolidaysConverter());
xstream.registerConverter(new FlightConverter());
xml = xstream.toXML(t);
Travels t1=(Travels)xstream.fromXML(xml);
}
XML
<Travels>
<Holidays>
<duration>10</duration>
<Flight>
<fid>255A</fid>
</Flight>
</Holidays>
<Holidays>
<duration>20</duration>
<Flight>
<fid>100B</fid>
</Flight>
</Holidays>
</Travels>
此代码给出了以下错误
线程“main”中的异常 com.thoughtworks.xstream.converters.ConversionException:null:null ----调试信息---- cause-exception:java.lang.RuntimeException cause-message:null class:Flight required-type:飞行转换器类型:FlightConverter路径: /旅行/假期/航班号码:4班[1]:假期 转换器类型[1]: com.thoughtworks.xstream.converters.reflection.ReflectionConverter class [2]:Travels版本:null