I have the following methods in my @Mapper
class:
@Mapping(source = "localCar.color", target = "color")
@Mapping(source = "blueBookCar.price", target = "price")
@Mapping(source = "localCar.features", target = "features", qualifiedByName = "mapFeatures")
abstract CarDto from(LocalCar localCar, BlueBookCar blueBookCar);
@Named("mapFeatures")
Map<Long, Feature> mapFeatures(Map<Group, Feature> features, BlueBookCar blueBookCar) {
// do stuff with both blueBookCar and features from localCar
}
However, I get a compile error stating no map struct method mapFeatures(Map)
found.
From this post, I tried to use @Context
blueBookCar
for both methods but then I get an error that it can be used to map in the from
method.
The only solution I can find is to pass in the blueBookCar
twice once annotated with @Context
and once without:
@Mapping(source = "localCar.color", target = "color")
@Mapping(source = "blueBookCar.price", target = "price")
@Mapping(source = "localCar.features", target = "features", qualifiedByName = "mapFeatures")
abstract CarDto from(LocalCar localCar, BlueBookCar blueBookCar, @Context BlueBookCar blueBookCar2)
@Named("mapFeatures")
Map<Long, Feature> mapFeatures(Map<Group, Feature> features, @Context BlueBookCar blueBookCar2) {
//do stuff with both blueBookCar and features from localCar
}
How can I use a parameter to map in both @Mapping
and @Named
methods?