I think I understand what your getting (maybe), so let me do a quick example.
You have 3 classes like:
Code:
public class PojoOne
{
private int id;
private String name;
private PojoTwo pojoTwo;
// Constructors, Getters and Setters below
}
public class PojoTwo
{
private int id;
private ArrayList<PojoThree> pojoThreeList;
// Constructors, Getters and Setters below
}
public class PojoThree
{
private int id;
private String name;
private String attribute;
// Constructors, Getters and Setters below
}
So as like you said, I have one class PojoOne which contains PojoTwo and that contains an ArrayList of PojoThree classes.
You can convert this to JSON and back to a PojoOne object (and all its sub objects) with Gson like so:
Code:
public class App
{
public static void main( String[] args )
{
PojoOne pojoOne = new PojoOne();
pojoOne.setId(0);
pojoOne.setName("myPojoOne");
pojoOne.getPojoTwo().setId(1);
pojoOne.getPojoTwo().getPojoThreeList().add(new PojoThree(2, "myPojoThree0", "hello world"));
pojoOne.getPojoTwo().getPojoThreeList().add(new PojoThree(3, "myPojoThree1", "bye world"));
Gson gson = new Gson();
String json = gson.toJson(pojoOne);
PojoOne obj = gson.fromJson(json, PojoOne.class);
}
}
And this maps it all perfectly back. (From this small example I've shown).
Is this what you were asking?
Bookmarks