java - xml skip root element -
so have following xml format in string:
<applist> <app stuff="blah"/> <app stuff="blah"/> </applist>
i wanting have list of app
so doing this:
xstream xstream = new xstream(); xstream.alias("applist", list.class); list<application> list = (list<application>) xstream.fromxml(xml); //xml above
and here entity object:
@xmlrootelement(name = "app") public class application{ private string stuff; public string getstuff() { return stuff; } public void setstuff(string stuff) { this.stuff = stuff; } }
i thought xstream.alias("applist", list.class);
supposed ignore root element... in case applist
. however, not working , getting exception.
exception in thread "main" com.thoughtworks.xstream.converters.conversionexception: app : app ---- debugging information ---- message : app cause-exception : com.thoughtworks.xstream.mapper.cannotresolveclassexception cause-message : app class : java.util.arraylist required-type : java.util.arraylist converter-type : com.thoughtworks.xstream.converters.collections.collectionconverter path : /applist/app line number : 4 version : null ------------------------------- @ com.thoughtworks.xstream.core.treeunmarshaller.convert(treeunmarshaller.java:79) @ com.thoughtworks.xstream.core.abstractreferenceunmarshaller.convert(abstractreferenceunmarshaller.java:65) @ com.thoughtworks.xstream.core.treeunmarshaller.convertanother(treeunmarshaller.java:66) @ com.thoughtworks.xstream.core.treeunmarshaller.convertanother(treeunmarshaller.java:50) @ com.thoughtworks.xstream.core.treeunmarshaller.start(treeunmarshaller.java:134) @ com.thoughtworks.xstream.core.abstracttreemarshallingstrategy.unmarshal(abstracttreemarshallingstrategy.java:32) @ com.thoughtworks.xstream.xstream.unmarshal(xstream.java:1058) @ com.thoughtworks.xstream.xstream.unmarshal(xstream.java:1042) @ com.thoughtworks.xstream.xstream.fromxml(xstream.java:913) @ com.thoughtworks.xstream.xstream.fromxml(xstream.java:904) @ teststuff.main(teststuff.java:19) caused by: com.thoughtworks.xstream.mapper.cannotresolveclassexception: app @ com.thoughtworks.xstream.mapper.defaultmapper.realclass(defaultmapper.java:56) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.dynamicproxymapper.realclass(dynamicproxymapper.java:55) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.packagealiasingmapper.realclass(packagealiasingmapper.java:88) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.classaliasingmapper.realclass(classaliasingmapper.java:79) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.arraymapper.realclass(arraymapper.java:74) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.mapperwrapper.realclass(mapperwrapper.java:30) @ com.thoughtworks.xstream.mapper.cachingmapper.realclass(cachingmapper.java:45) @ com.thoughtworks.xstream.core.util.hierarchicalstreams.readclasstype(hierarchicalstreams.java:29) @ com.thoughtworks.xstream.converters.collections.abstractcollectionconverter.readitem(abstractcollectionconverter.java:70) @ com.thoughtworks.xstream.converters.collections.collectionconverter.addcurrentelementtocollection(collectionconverter.java:79) @ com.thoughtworks.xstream.converters.collections.collectionconverter.populatecollection(collectionconverter.java:72) @ com.thoughtworks.xstream.converters.collections.collectionconverter.populatecollection(collectionconverter.java:66) @ com.thoughtworks.xstream.converters.collections.collectionconverter.unmarshal(collectionconverter.java:61) @ com.thoughtworks.xstream.core.treeunmarshaller.convert(treeunmarshaller.java:72) ... 10 more
so why getting exception? think parse pretty nicely this.
update:
i added xstream.alias("app", application.class);
, putting objects list. however, value of stuff
null
i implemented system using xstream , didn't find major issues, great library work xml :)
i believe not need register "list.class
" "application.class
".
i following:
xstream xstream = new xstream(new staxdriver()); xstream.alias("app", application.class); xstream.useattributefor(application.class, "stuff"); list<application> list = (list<application>) xstream.fromxml(xml);
let me know if works you. happy coding!!!
Comments
Post a Comment