java - XML conversion by using XStream : not able parse date of format 2016-02-04T18:01 -


i converting xml using xstream.

my xml looks below.

<reportunit>     <creationdate>2016-02-04t18:01</creationdate>     <description>days late report</description>     <label>days late report</label>     <permissionmask>2</permissionmask>     <updatedate>2014-10-31t19:45</updatedate> </reportunit> 

my java code converting xml

xstream xstream = new xstream(); xstream.alias("reportunit", reportunit.class); xstream.registerconverter(             new com.thoughtworks.xstream.converters.basic.dateconverter("yyyy-mm-dd hh:mm", new string[] {"dd/mm/yyyy hh:mm"},new gregoriancalendar().gettimezone()){               public boolean canconvert(class type) {                     return type.equals(date.class) || type.equals(timestamp.class);               }               public string tostring(object obj) {                   return new simpledateformat("yyyy-mm-dd hh:mm").format((date) obj);               }         });  xstream.fromxml(objectxml.replace("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>", blank)); 

the above code works date format

<creationdate>2016-02-04 18:01</creationdate> 

but not

<creationdate>2016-02-04t18:01</creationdate> 

i getting exception : cannot parse date 2016-02-04t18:01

i tried using iso8601dateconverter thoughtworks available @ below package

"com.thoughtworks.xstream.converters.extended.iso8601dateconverter"

but did not resolve issue ...

did had same issue , know how resolve same.

the format incorrect. when used "yyyy-mm-dd't'hh:mm" format worked me.

xstream xstream = new xstream(); xstream.alias("reportunit", reportunit.class); xstream.registerconverter(             new com.thoughtworks.xstream.converters.basic.dateconverter("yyyy-mm-dd't'hh:mm", new string[] {"dd/mm/yyyy hh:mm"},new gregoriancalendar().gettimezone()){               public boolean canconvert(class type) {                     return type.equals(date.class) || type.equals(timestamp.class);               }               public string tostring(object obj) {                   return new simpledateformat("yyyy-mm-dd hh:mm").format((date) obj);               }         });  xstream.fromxml(objectxml.replace("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>", blank)); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -