无法为嵌入式实体中的字段分配值

时间:2018-07-29 08:53:13

标签: android-room

我正在从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文件:

enter image description here

我可以接收/访问MyLoginSession中的值,包括sessionIDmessagestudentCount,以及{{1 }}。但是问题是我无法收到学生的值,这是StudentWithHomeworkAttendance下唯一的嵌入式实体。下面是调试器中变量myLoginSession的屏幕截图。

enter image description here

如您在上图底部所示,未设置学生的值。我在这里做错了什么?

0 个答案:

没有答案