How to serialize/deserialize partial JSON object using GSON? How to serialize/deserialize partial JSON object using GSON? json json

How to serialize/deserialize partial JSON object using GSON?


You can use JsonElement. For example:

 class DataObject{        @Expose @Serialize("a")        DataA A;        @Expose @Serialize("b")        DataB B;        @Expose @Serialize("not-required-a")        JsonElement NotRequired;        ... }


i think its the solution .make a view Model and make get and setter method.

YourClass class = gson.fromJson(jsonText , YourClass .class);   class.getA();class.getB();

point:for gson you should implement all Features in json text.for example you have a object called not-required-1 .make a class not-required-1 and set not-required-2 array at that class .

you viewModel Example.

public class ViewModel(){   A a;   B b;   not-required-1 Not-required-1;}

your not-required-1 for example:

public class not-required-1(){   ArrayList<String> not-required-2 = new ArrayList<String>();}

your not-required-1 for example: