I’m using Mapstruct to define a Mapper like this:
@Mapper(componentModel = "spring")
@DecoratedWith(DecoratorMapper.class)
public interface Mapper {
@Mapping(target = "data", source = "source.data")
Target toTarget(final Source source);
Here you can see I use an abstract class as a decorator. What i’d like to do in it is something like this :
public abstract class DecoratorMapper implements Mapper{
@Override
@Mapping(target = "data", expression = "java(SpecificUtils.doStuff(source.getData()))")
public abstract Target toTarget(Source source);
But it doesn’t work no override is generated in the implementation class, the only working thing for me so far was making toTarget not abstract and explicitly write code in it.
Do you know of a way to have mappings in the decorated as well as in the decorator’s overrides ?
I tried to use an abstract class for the decorated instead of an interface, that doesn’t seem to change anything. I expected to be able to use mapstruct as well to generate the overrides in my decorator.
dovahkiin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.