博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
xstream 别名的用法<转>
阅读量:7238 次
发布时间:2019-06-29

本文共 1462 字,大约阅读时间需要 4 分钟。

1.xstream的alias使用方法:

       1.1 作用:将序列化中的类全量名称,用别名替换。
       1.2  使用方法:xstream.alias("blog", Blog.class);
       1.3  示例:
            要序列化的类:
package test.xstream.test;
public class Author {
    private String name;
    public Author(String name) {
            this.name = name;
    }
    public String getName() {
            return name;
    }
}
        不使用别名alias时序列化出来的xml:
<test.xstream.test.Author>
  <name>name</name>
</test.xstream.test.Author>
使用别名alias时序列化出来的xml:
<Author>
  <name>name</name>
</Author>
2.xstream的aliasField
     2.1 作用:使用别名替代属性名
     2.2 使用方法:xstream.aliasField("author", Author.class, "name");
    2.3 示例:
不使用别名aliasField时序列化出来的xml:
<Author>
  <name>name</name>
</Author>
使用别名aliasField时序列化出来的xml:
<Author>
  <author>name</author>
</Author>
    3. xstream的useAttributeFor    
3.1 作用:将某一个类的属性,作为xml头信息的属性,而不是子节点    
3.2 使用方法:xstream.useAttributeFor(Author.class, "name");   
3.3  示例: 不使用别名useAttributeFor时序列化出来的xml:
<Author> <author>name</author> </Author>
使用别名useAttributeFor时序列化出来的xml:
<Author name="name"/>
    ps: 使用方法
    public static void main(String[] args) {
        XStream xstream = new XStream();
        xstream.alias("Author", Author.class);
//        xstream.aliasField("author", Author.class, "name");
        xstream.useAttributeFor(Author.class, "name");
        Author author =new Author("name");
        String xmlString =xstream.toXML(author);
        System.out.println(xmlString);
    }
几个相关网址:http://xstream.codehaus.org/alias-tutorial.html
http://blog.csdn.net/faye0412/article/details/6602144

 

原文链接:http://blog.csdn.net/subuser/article/details/21548227

转载于:https://www.cnblogs.com/tanglc/p/4439340.html

你可能感兴趣的文章
windows 2008 怎么对外开放端口
查看>>
[cocos2d-x 3.0] 触摸显示器
查看>>
Linux 修改计算机名
查看>>
python --subprocess 范例
查看>>
菜鸟学SSH(十二)——Hibernate与Spring配合生成表结构
查看>>
Python IO多路复用
查看>>
docfx组件介绍--YamlSerialization
查看>>
由于没有远程桌面授权服务器可以提供许可证,远程会话被中断。
查看>>
ThinkPHP Where 条件中使用表达式
查看>>
使用ShareSDK完成Facebook第三方登录和Facebook分享时没办法跳转到Facebook应用
查看>>
redis错误总结
查看>>
Device Administration
查看>>
eclipse Reference 功能之——项目之间的引用
查看>>
jdk7和8的一些新特性介绍
查看>>
Linux中查看jdk版本
查看>>
iOS 应用的生命周期
查看>>
Linux下文件的压缩和解压
查看>>
oracle 的PACKAGE恢复过程
查看>>
ODI学习笔记2--ODI产品架构
查看>>
op挂载摄像头
查看>>