We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I am trying to achieve the following but not sure if this is what this extensions is meant for. I am a bit confused.
I will like to inject a custom service in the CarMapper interface extending the Spring Converter.
It seems injection is not possible with CarMapper interface but only with abstract classes.
Is it possible to achieve this while keeping the integration with the Spring ConversionService?
@Mapper(componentModel = "spring") public interface CarMapper extends Converter<Car, CarDto> { @Autowired private MyCustomService myCustomService;//This is not working @Mapping(target = "title", expression = "java(getLocaleTitle(car))) CarDto convert(Car car); default String getLocaleTitle(Car car) { return myCustomService.translate(car.getTitle()); } }
Usage:
@Autowired private ConversionService conversionService; ... Car car = ...; CarDto carDto = conversionService.convert(car, CarDto.class);
The text was updated successfully, but these errors were encountered:
Why don't you make the Mapper an abstract class instead? By the way, this doesn't require the extension at all. As the documentation says:
All this can be achieved already with MapStruct’s core functionality.
With or without the extension, nothing prevents you from writing
public abstract class CarMapper implements Converter<Car, CarDto>
Sorry, something went wrong.
@Chessray Thanks you it did work. Sorry for the confusion!
No branches or pull requests
I am trying to achieve the following but not sure if this is what this extensions is meant for. I am a bit confused.
I will like to inject a custom service in the CarMapper interface extending the Spring Converter.
It seems injection is not possible with CarMapper interface but only with abstract classes.
Is it possible to achieve this while keeping the integration with the Spring ConversionService?
Usage:
The text was updated successfully, but these errors were encountered: