无法从 Flux<Object> 转换为 Flux<BOLCompliance>
Cannot convert from Flux<Object> to Flux<BOLCompliance>
我在下面的方法中遇到了这个错误
“return Mono.justOrEmpty(routeLink.getComplianceIds())”
private Flux<BOLCompliance> getComplienceRouteLink(BOLRouteLink routeLink, BillOfLadingResponse bol) {
return Mono.justOrEmpty(routeLink.getComplianceIds())
.flatMapMany(Flux::fromIterable)
.flatMap(id -> complianceCaller.getComplianceById(id))
.map(compliance -> createComplianceResponse(compliance, bol));
}
routeLink.getComplianceIds() returns 一个字符串类型的列表,
createComplianceResponse returns 类型为 BOLCompliance 的 Mono 和 complianceCaller.getComplianceById(id)) returns 类型为 Compliance
的 Mono
public Mono<Compliance> getComplianceById(String complianceID);
private Mono<BOLCompliance> createComplianceResponse(Compliance compliance, BillOfLadingResponse bol);
你的
.map(compliance -> createComplianceResponse(compliance, bol));
应该是
.flatMap(compliance -> createComplianceResponse(compliance, bol));
因为您的 return 类型是 Mono<BOLCompliance>
for createComplianceResponse
,并且您希望 BOLCompliance
继续向下移动,而不是 Mono
对象.在您的示例中,生成的 Flux 是 Flux<Mono<BOLCompliance>>
.
我在下面的方法中遇到了这个错误 “return Mono.justOrEmpty(routeLink.getComplianceIds())”
private Flux<BOLCompliance> getComplienceRouteLink(BOLRouteLink routeLink, BillOfLadingResponse bol) {
return Mono.justOrEmpty(routeLink.getComplianceIds())
.flatMapMany(Flux::fromIterable)
.flatMap(id -> complianceCaller.getComplianceById(id))
.map(compliance -> createComplianceResponse(compliance, bol));
}
routeLink.getComplianceIds() returns 一个字符串类型的列表, createComplianceResponse returns 类型为 BOLCompliance 的 Mono 和 complianceCaller.getComplianceById(id)) returns 类型为 Compliance
的 Monopublic Mono<Compliance> getComplianceById(String complianceID);
private Mono<BOLCompliance> createComplianceResponse(Compliance compliance, BillOfLadingResponse bol);
你的
.map(compliance -> createComplianceResponse(compliance, bol));
应该是
.flatMap(compliance -> createComplianceResponse(compliance, bol));
因为您的 return 类型是 Mono<BOLCompliance>
for createComplianceResponse
,并且您希望 BOLCompliance
继续向下移动,而不是 Mono
对象.在您的示例中,生成的 Flux 是 Flux<Mono<BOLCompliance>>
.