I have a mapper
@Mapper(uses = {PostConverter.class, TagConverter.class})
public interface TagMapper {
void update(TagRequestDTO source, @MappingTarget Tag destination);
Tag dtoToTag(TagRequestDTO dto);
TagResponseDTO tagToDTO(Tag tag);
Tag longToTag(Long id);
}
Is there a way to set the behavior of mapstruct so that it uses a method from TagConverter, rather than generating its own? (using default methods and abstract classes is not possible)
Converter
public interface TagConverter {
Tag longToTag(Long id);
Set<Long> fromTagsToLong(Set<Tag> tags);
Set<Tag> fromLongsToTags(Set<Long> ids);
}
Implementation
@Component
@RequiredArgsConstructor
public class TagConverterImpl implements TagConverter {
private final TagRepository repository;
@Override
public Tag longToTag(Long id) {
return repository.findById(id).orElseThrow(() -> new EntityNotFoundException("Tag", id));
}
}
I read the MapStruct docs, but didn’t find a solution.
Mihena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.