XStream转换XML之格式转换问题

来源:互联网 发布:软件icon图标素材 编辑:程序博客网 时间:2024/05/17 15:41
// 日期转换期xstream.registerConverter(new DateConverter("yyyy-MM-dd'T'hh:mm:ss",null));
格式:"yyyy-MM-dd'T'hh:mm:ss"

结果:2012-05-24T14:01:09

未转换前:2012-05-24 02:12:23.089 UTC

转换后:2012-05-24T02:12:23


//属性重命名xstream.aliasField("邮件", Student.class, "mails");
未加别名前:<mails>

加了别名后:<邮件>


//包重命名xstream.aliasPackage("oo","com.model");

未加别名前:<com.model.Student>

加了别名后:<oo.Student>


//类重命名xstream.alias("Student",Student.class);
未加别名前:<com.model.Student>

加了别名后:<Student>


//添加隐式集合xstream.addImplicitCollection(Student.class, "mails");
未添加前:

<mails>
    <com.model.Mail>
      <name>163</name>
      <email>test@163.com</email>
    </com.model.Mail>
    <com.model.Mail>
      <name>263</name>
      <email>test@263.net</email>
    </com.model.Mail>
  </mails>

添加后:

<com.model.Mail>
    <name>163</name>
    <email>test@163.com</email>
  </com.model.Mail>
  <com.model.Mail>
    <name>263</name>
    <email>test@263.net</email>
  </com.model.Mail>


//设置节点的属性xstream.useAttributeFor(Student.class, "name");
效果:<com.model.Student name="名字">


原创粉丝点击