I am trying to build a list of responses from a list of entities (DB).
To construct my list of responses, I am using parallelStream and in the mapper, I am trying to call another microservice but the problem is that only one result is injected into my response instead of each item response in the list.
Use case
companyPartnerships.parallelStream()
.map(partnershipItemMapper::toPartnershipItemResponse)
.collect(Collectors.toList());
Mapper
@Mapping(target = "balance", source = ".", qualifiedByName = "injectBalanceToPartnershipItemResponse")
public abstract PartnershipItemResponse toPartnershipItemResponse(Partnership partnership);
@Named("injectBalanceToPartnershipItemResponse")
protected Long injectBalanceToPartnershipItemResponse(Partnership partnership) {
return partnershipMetricsProxy.getPartnershipMetricsFor(partnership.getId())
.map(PartnershipMetrics::getBalance)
.orElse(null);
}
Example of response
{
"id": 473,
"balance": null
},
{
"id": 617,
"balance": 26122
},
{
"id": 517,
"balance": null
}