I've searched for a lot of time and I cannot find a way to solve this problem. In my spring application I have a BesoinPoseMapper
@FunctionalInterface
@Mapper(uses = BesoinPoseTranslator.class)
public interface BesoinPoseMapper {
@Mappings({
@Mapping(target = "nbCapteurs", source = "valeur", qualifiedByName = {"BesoinPoseTranslator", "nbCapteurs"}),
@Mapping(target = "typologie", source = "typologie", qualifiedByName = {"BesoinPoseTranslator", "typologie"}),
@Mapping(target = "site", source = "site", qualifiedByName = {"BesoinPoseTranslator", "emplacement"})
})
BesoinPoseDTO entityToDTO(BesoinPoseEntity entity);
}
To map the BesoinPoseEntity into BesoinPoseDTO
However the map function in BesoinPoseController
public class BesoinPoseController {
@Setter
@Autowired
private BesoinPoseRepository besoinPoseRepo;
@GetMapping()
public List<BesoinPoseDTO> getBesoinsPose(@RequestParam String range, @RequestParam(required = false) String status){
return StreamSupport.stream(besoinPoseRepo.findAll().spliterator(), false)
.map(BesoinPoseMapper::entityToDTO)
.collect(Collectors.toList());
}
}
throws a compilation error
.map(BesoinPoseMapper::entityToDTO);
^
required: Function<? super BesoinPoseEntity,? extends R>
found: BesoinPose[...]ToDTO
reason: cannot infer type-variable(s) R
(argument mismatch; invalid method reference
cannot find symbol
symbol: method entityToDTO(BesoinPoseEntity)
location: interface BesoinPoseMapper)
where R,T are type-variables:
R extends Object declared in method <R>map(Function<? super T,? extends R>)
T extends Object declared in interface Stream
I've tried using lambdas and changing types from iterable to list and arrays and back to streams but to no avail, the error persists. The compiler cannot infer that the R type is BesoinPoseDTO .
Is there anyway to fix this ?
Thanks