I have this classes:
class Student {
String student_id;
String name;
List<GradeValue> grades;
}
class Grades {
String id;
String student_id;
Long grade_value;
}
class GradeValue {
Long grade_value;
}
I'm trying to use JOOQ to make a query that returns all students with all the grade values.
For this to happen I have to join the student and grades tables but then I should convert the grade to a grade value and I'm not sure how to do this.
List<Student> students = dsl.select(jsonObject(
jsonEntry("id", STUDENT.STUDENT_ID),
jsonEntry("name", STUDENT.NAME),
jsonEntry("grades", field(
select(jsonbObjectAgg(GRADES.GRADE_VALUE))
.from(GRADES)
.where(GRADES.STUDENT_ID.eq(STUDENT.STUDENT_ID))
))
)).from(STUDENT)
.fetchInto(Student.class);
Gives me this error:
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of
java.util.ArrayList<GradeValue>
out of START_OBJECT token at [Source: (String)"{"id" : "1", "name" : "test", "grades" : {"grade_value": 10}}"; line: 1, column: 99]
Any ideias?
Thanks