我试图转换的XML看起来像:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfTrafiklage>
<Trafiklage>
<Utgangsdatum xmlns="">2011-10-14T00:00:00+02:00</Utgangsdatum>
</Trafiklage>
<Trafiklage>
<Utgangsdatum xmlns="">2011-10-15T00:00:00+02:00</Utgangsdatum>
</Trafiklage>
<Trafiklage>
<Utgangsdatum xmlns="">2011-10-16T00:00:00+02:00</Utgangsdatum>
</Trafiklage>
</ArrayOfTrafiklage>
我要转换的代码如下所示:
XStream xstream = new XStream(new DomDriver());
xstream.alias("ArrayOfTrafiklage", Trafiklagen.class);
xstream.alias("Trafiklage", StationInfoModel.class);
Trafiklagen trafiklagen = (Trafiklagen) xstream
.fromXML(result);
StationInfoModel.java看起来像:
public class StationInfoModel
{
private Date Utgangsdatum;
}
我在运行fromXML命令时遇到此异常:
com.thoughtworks.xstream.converters.ConversionException: Utgangsdatum : Utgangsdatum
---- Debugging information ----
message : Utgangsdatum
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : Utgangsdatum
class : java.util.ArrayList
required-type : java.util.ArrayList
converter-type : com.thoughtworks.xstream.converters.collections.CollectionConverter
path : /ArrayOfTrafiklage/Trafiklage/Utgangsdatum
class[1] : org.rickardp.trainstatus.Models.Trafiklagen
converter-type[1] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
version : 0.0
-------------------------------
有人知道我做错了吗?
答案 0 :(得分:0)
看看这个blog article
答案 1 :(得分:0)
使用此
private static SimpleDateFormat frmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
frmt.format(date)