我有一个网络服务,返回学生和注册班级的详细信息。
{
"name": "student-name",
"classes": [
{
"className": "reactor-101",
"day": "Tuesday"
},
{
"className": "reactor-102",
"day": "Friday"
}
]
}
该类的DTO如下:
public class Student {
private String name;
private Flux<StudentClass> classes;
@Data
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public static class StudentClass {
private String className;
private String day;
}
}
Flux<StudentClass> studentClassFlux = studentClassRepository.getStudentClass(studentName);
return Mono.just(new Student(studentName, studentClassFlux));
问题是,在进行REST调用后,我得到了以下输出:
{
"name": "student-name",
"classes": {
"prefetch": 32,
"scanAvailable": true
}
}
我可以通过阻塞通量请求来实现所需的输出,以完成该请求,然后将输出转换为列表。
List<StudentClass> studentClassList = studentClassRepository.getStudentClass(studentName)..toStream().collect(Collectors.toList());
return Mono.just(new Student(studentName, studentClassList)); // Change the Student#classes from flux to list
使用通量的正确方法是什么;Mono在这里获得所需的输出?