实体
public class User {
@Since(value = 3)//大于这个值正常导出
public String name;
@Until(value = 4) //小于这个值正常导出
public int age;
@SerializedName(value = "email_Address",alternate = {"email","Address"})
public String emailAddress;
private String phone;
......
}
执行
public static void main(String[] args) throws IOException {
User user = new User();
user.setAge(100);
user.setEmailAddress("山西省运城市");
user.setName("gy");
user.setPhone("1808888888");
Gson gson = new GsonBuilder().setVersion(4).create();
String result = gson.toJson(user);
System.out.println("result==="+result);//{"name":"gy","email_Address":"山西省运城市","phone":"1808888888"}
String str = "{\"name\":\"gy\",\"age\":100,\"email_Address\":\"山西省运城市\",\"phone\":\"1808888888\"}";
User user1 = gson.fromJson(str,User.class);
System.out.println("use=="+user1.getName());//Version 大于3 use==gy Version小于3 use==null
}