我有这个图象:
public class Student {
public String name;
public School school;
}
public class School {
public int id;
public String name;
}
public class Data {
public ArrayList<Student> students;
public ArrayList<School> schools;
}
我愿将数据标同Gson编成序列,并取得以下内容:
{ "students": [{
"name":"name1",
"school": "1" //the id of the scool, not its entire Json
}],
"school": [{ //the entire JSON
"id" : "1",
"name": "schoolName"
}]
}
为此,我必须使用学生的定制序列器,以便Gson只印刷学校的id。 但对于学校而言,我必须拥有正式的序列仪。
我怎么能与只有一个Gson物体做任何事?