<?xml version="1.0" encoding="UTF-8" ?> <person> <name>yunyun</name> <gender>true</gender> <address>shanghai</address> <contents>cc</contents> <contents>ss</contents> <taxs> <string>1</string> <string>2</string> <string>3</string> </taxs> </person>
public class Person2 { private String name; private boolean gender; private String homeAddress; private List<String> contentslist; private String[] taxs; @Override xstream 解析xml 别名 注解 list集合 boolean 数组 converter Pom.xml设置 - fengfan - 我的博客 public String toString() { return ToStringBuilder.reflectionToString(this); } }
public class TestXmlToObject2 { public static final XStream xstream=new XStream(); xstream 解析xml 别名 注解 list集合 boolean 数组 converter Pom.xml设置 - fengfan - 我的博客 static{ xstream.alias("person", Person2.class);//类别名 xstream.aliasField("address", Person2.class, "homeAddress"); //属性别名 xstream.alias("contents",String.class);//private List<String> contentslist;是string类型 xstream.addImplicitCollection(Person2.class, "contentslist");//隐式集合 隐藏contentslist Person2 person=(Person2)xstream.fromXML(TestXmlToObject2.class.getClassLoader().getResourceAsStream("person02.xml")); System.out.println(person.toString()); } xstream 解析xml 别名 注解 list集合 boolean 数组 converter Pom.xml设置 - fengfan - 我的博客 public static void main(String[] args) { } }