@XStreamAlias("person")
public class Person {
@XStreamAlias("name")
private String name="";
@XStreamAlias("sex")
private String sex="";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
main方法
public class PersonTest {
public static void main(String[] args) {
Person person = new Person();
person.setName("hehe");
XStream xStream = new XStream(new DomDriver());
xStream.processAnnotations(Person.class);
System.out.println(xStream.toXML(person));
}
发布评论
评论(1)
只需要在定义bean时给每一个成员变量赋一个空字符串的默认值,举个例子:
main方法
输出结果:
<person>
<name>hehe</name>
<sex></sex>
</person>