Create JSON String using GSON

后端 未结 5 2016
梦毁少年i
梦毁少年i 2021-02-05 09:29

I am having a class like following,

public class Student {
    public int id;
    public String name;
    public int age;    
}

Now I want to c

5条回答
  •  [愿得一人]
    2021-02-05 09:32

    You can explore the json tree with gson.

    Try something like this :

    gson.toJsonTree(stu1).getAsJsonObject().remove("id");
    

    You can add some properties also :

    gson.toJsonTree(stu2).getAsJsonObject().addProperty("id", "100");
    

提交回复
热议问题