我有两个java类......
public class Item {
private int itemIndex;
private String containerType;
private Map<String, List<String>> contentType;
private String status;
private List<String> remark;
// their getters and setters
}
请告诉我如何将Item对象转换为xml和xml转换为Item对象?我用过XStream jar进行转换。我需要在xml中存储多个Item(项目列表)。请在JAVA中提供完整的编码,以添加包含现有项目的新项目(以xml格式存储)。
答案 0 :(得分:2)
ObjectOutputStream out = xstream.createObjectOutputStream(someWriter);
out.writeObject(new Person("Joe", "Walnes"));
out.writeObject(new Person("Someone", "Else"));
out.writeObject("hello");
out.writeInt(12345);
out.close();