开发者

XStream conversion exception on a xml date and time string

The XML i trying to convert looks like:

<?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>

My code to convert looks like this:

XStream xstream = new XStream(new DomDriver());

xstream.alias("ArrayOfTrafiklage", Trafiklagen.class);
xstream.alias("Trafiklage", StationInfoModel.class);

Trafiklagen trafiklagen = (Trafiklagen) xstream
        .fromXML(result);

The StationInfoModel.java looks like:

public class StationInfoModel 
{
    private Date Utgangsdatum;
}

And i getting this Exception when it running the fromXML command:

com.thoughtworks.xstream.converters.ConversionException: Utgangsdatum : Utgangsdatum
---- Debugging information ----
message             : Utgangsdatum
cause-exception     : com.thoughtworks.xs开发者_如何转开发tream.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
-------------------------------

Do someone has any idea what i doing wrong?


Use this

private static SimpleDateFormat frmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
frmt.format(date)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜