You don't necessarily need a CustomConverter.
You need a class to hold your list:
public class PersonList {
private List<Person> list;
public PersonList(){
list = new ArrayList<Person>();
}
public void add(Person p){
list.add(p);
}
}
To serialise the list to XML:
XStream xstream = new XStream();
xstream.alias("person", Person.class);
xstream.alias("persons", PersonList.class);
xstream.addImplicitCollection(PersonList.class, "list");
PersonList list = new PersonList();
list.add(new Person("ABC",12,"address"));
list.add(new Person("XYZ",20,"address2"));
String xml = xstream.toXML(list);
To deserialise xml to a list of person objects:
String xml = "<persons><person>...</person></persons>";
PersonList pList = (PersonList)xstream.fromXML(xml);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…