Gson @Expose熟悉和@SerializedName属性

原文链接: http://www.cnblogs.com/butterfly-clover/p/5788657.html

这两个属性一般配套使用。

1.@Expose标签的2个属性.
    deserialize
 (boolean) 反序列化 默认 true
       serialize  (boolean) 序列化 默认 true

   创建Gson对象,没有@Expose注释的属性将不会被序列化

2.使用@SerializedName标签定义属性序列化后的名字

示例:

public class Persion {

    @Expose
    @SerializedName("name")
    private String name;

    @Expose
    @SerializedName("age")
    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;
    }
}

转载于:https://www.cnblogs.com/butterfly-clover/p/5788657.html

猜你喜欢

转载自blog.csdn.net/weixin_30713953/article/details/94861014