我有两个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 中存储多个项目(项目列表)。请提供完整的 JAVA 编码,以将新项目添加到现有项目(存储在 xml 中)。
最佳答案
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();
关于java - 带有 xml 和 java 对象的 XStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3888253/