I have this schema :
public class Student { public String name; public School school; } public class School { public int id; pub
Of course wherever you are going to serialize this object you need to add it to the Gson like this:
Gson gson = new GsonBuilder() .registerTypeAdapter(Student.class, new StudentAdapter()) .create(); return gson.toJson([YOUR_OBJECT_TO_BE_SERIALIZED]);