0

I've the following test code which is not working.

    XStream xStream = new XStream(new DomDriver());
    xStream.alias(clazz.getName(), clazz);
    String test="<list><Person><lastname>abcd</lastname><phone><code>123</code><number>1234-456</number></phone><fax><code>123</code><number>9999-999</number></fax></Person></list>";
    Object object = xStream.fromXML(test);


    clazz=Arraylist.class

Exception Information:

com.thoughtworks.xstream.converters.ConversionException: Person : Person : Person : Person
---- Debugging information ----
message             : Person : Person
cause-exception     : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message       : Person : Person
class               : java.util.ArrayList
required-type       : java.util.ArrayList
path                : /list/Person
4

1 回答 1

1

XStream 似乎不知道是什么Person,这是有道理的,因为您没有在任何地方给它起别名。

尝试添加

xStream.alias("Person", Person.class);
于 2012-05-11T16:47:31.293 回答