怎样让xstream在生成xml时,显示null属性。如:
class Admin extends Person {
public String name;
public boolean online;
public Map mailMap = null;
public Admin(String name, boolean online, Map<String, String> mailMap) {
this.name = name;
this.online = online;
this.mailMap = mailMap;
}
public String toString() {
return super.toString() + "Admin{" +
"name=" + name +
",online=" + online +
",mailMap=" +
mailMap.toString()
+ "}";
}
}
Admin admin = new Admin("me", true, null);
XStream xs = new XStream();
System.out.println(xs.toXML(admin));
//运行结果
me
true
//其中没有mailMap属性,我想要下面的效果:
me
true