我正在从RESTful API接收数据到我的对象,该对象声明如下:
public class MyLoginSession {
private String sessionID, message;
private int result = 0, studentCount = 0;
public List<StudentWithHomeworkAttendance> students = new ArrayList<>();
public boolean isLoggedIn;
public void setResult(int result) {
this.result = result;
}
public int getResult() {
return result;
}
public void setSessionID(String sessionID) {
this.sessionID = sessionID;
}
public String getSessionID() {
return sessionID;
}
public void setStudentCount(int studentCount) {
this.studentCount = studentCount;
}
public int getStudentCount() {
return studentCount;
}
public void setStudents(List<StudentWithHomeworkAttendance> students){
this.students = students;
}
public List<StudentWithHomeworkAttendance> getStudents(){
return students;
}
public void setMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setLoggedIn(boolean loggedIn) {
isLoggedIn = loggedIn;
}
public boolean isLoggedIn() {
return isLoggedIn;
}
}
StudentWithHomeworkAttendance声明如下:
class StudentWithHomeworkAttendance {
@Embedded
var students = Student()
@Relation(parentColumn = "studentID", entityColumn = "studentID", entity = Homework::class)
var homework: List<Homework> = arrayListOf()
@Relation(parentColumn = "studentID", entityColumn = "studentID", entity = Attendance::class)
var attendance: List<Attendance> = arrayListOf()
}
学生声明如下:
@Entity(tableName = "student")
data class Student(@PrimaryKey(autoGenerate = true) var id: Long = 0,
@ColumnInfo(name="studentID") var studentID: Long = 0,
@ColumnInfo(name="schoolID") var schoolID: Long = 0,
@ColumnInfo(name="guardianID") var guardianID: String = "",
@ColumnInfo(name="matrixNumber") var matrixNumber: String = "",
@ColumnInfo(name="ic") var ic: String = "",
@ColumnInfo(name="year") var year: Int = 0,
@ColumnInfo(name="name") var name: String = "",
@ColumnInfo(name="surname") var surname: String = "",
@ColumnInfo(name="kelas") var kelas: String = "",
@ColumnInfo(name="guruKelas") var guruKelas: String = "",
@ColumnInfo(name="guruKelasEmail") var guruKelasEmail: String = "",
@ColumnInfo(name="picture") var picture: String = "",
@ColumnInfo(name="status") var status: Int = 0,
@ColumnInfo(name="ayah") var ayah: String = "",
@ColumnInfo(name="emak") var emak: String = ""
) { }
以下是MyLoginSession接收的JSON文件:
我可以接收/访问MyLoginSession
中的值,包括sessionID
,message
,studentCount
,以及{{1 }}。但是问题是我无法收到学生的值,这是StudentWithHomeworkAttendance
下唯一的嵌入式实体。下面是调试器中变量myLoginSession的屏幕截图。
如您在上图底部所示,未设置学生的值。我在这里做错了什么?