Android
来源:互联网 发布:网络诈骗案例分析 编辑:程序博客网 时间:2024/06/05 16:49
@Expose
注解可以标明哪些字段进行序列化
例子
User 类
可以看见
name
属性 被@Expose
修饰
class User { @Expose private String name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; }}
示例 1
创建普通的 Gson
Gson gson1 = new GsonBuilder().create(); User user1 = new User(); user1.setName("yuan"); user1.setAge(15); System.out.println("user1 = " + gson1.toJson(user1));
输出
user1 = {"name":"yuan","age":15}
示例2
创建
excludeFieldsWithoutExposeAnnotation
Gson
Gson gson2 = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); User user2 = new User(); user2.setName("ming"); user2.setAge(18); System.out.println("user2 = " + gson2.toJson(user2));
输出
user2 = {"name":"ming"}
结果
如果创建 excludeFieldsWithoutExposeAnnotation
的 Gson
,那么只解析 @Expose
注解标识的属性。
阅读全文
0 0
- Android
- android
- Android
- android
- android
- Android
- Android
- android
- android
- android
- Android
- Android
- android!!!
- android
- android
- android
- android
- android:
- VS 2015 linux makefile
- sticky-headers-recyclerview库使用出现的问题
- Xmind工具使用
- JAVA HASHMAP 用法
- #比特币挖矿part1# 挖矿算法
- Android
- 多线程-实例变量与线程安全
- eclipse只能运行,不能调试的解决办法-Initializing Spring FrameworkServlet 'dispatcherServlet'
- 多环境支持-Maven和Spring的Profile
- android关于6.0权限 ActivityCompat.requestPermissions找不到问题
- tomcat移植到weblogic时,sun.awt.X11GraphicsEnvironment报错和html页面显示中文乱码
- CentOS7安装使用Docker
- Python安装模块(numpy等)问题的两种解决办法——常规方法和Anaconda
- 人口普查