Answer the question
In order to leave comments, you need to log in
How to properly use mapstruct with mapping parameters?
Hello.
So the situation is this.
//Есть сущность
public class MyObject {
public Word word; // имеет множество переводов, содержит в себе
}
//и необходимо смапить в сущность с переводом
public class MyObjectDto {
public String wordValue; // имеет множество переводов, содержит в себе
}
@Component
public class CustomMapper {
public String converterMapper(Word word, Language lang)
}
@Mapper(componentModel = "spring", uses = CustomMapper.class)
public interface MyObjectMapper {
//И почему не всегда @Autowired CustomMapper из-за этого не могу использовать expression
@Mappings({
@Mapping(source = "word", target = "wordValue", qualifiedBy=(CustomMapper.class???)) //как передать параметр
});
MyObjectDto map(MyObject mo);
MyObject map(MyObjectDto myObjectDto);
}
Answer the question
In order to leave comments, you need to log in
So that's how it was done.
@Mapper(componentModel = "spring", uses = CustomMapper.class)
public interface MyObjectMapper {
@Mappings({
@Mapping(target = "field", expression = "java(customMapper.convert(obj.field, lang))"
})
DTO map(Entity obj, Language lang);
}
componentModel = "spring"
...
CarMapper INSTANCE = Mappers.getMapper( CarMapper.class );
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question