Using additional parameter in MapStruct named mapper method does not compile

26 Views Asked by At
@Component
@Mapper(componentModel = "spring")
public abstract class OrderMapper {

    @Autowired
    private ObjectMapper objectMapper;

    @Mapping(source = "type", target = "type")
    @Mapping(source = "resource.data", target = "properties", qualifiedByName = "toOrderDetails")
    public abstract Order toEntity(final OrderResource resource, final String type);

    @Named("toOrderDetails")
    public OrderDetails maptoOrderDetails(final Map<String, Object> data, @Context final String type) {
        // handle data and type...
        return new OrderDetails();
    }
}

This gives the following error messages when compiling:

error: Qualifier error. No method found annotated with @Named#value: [ toOrderDetails ]. See https://mapstruct.org/faq/#qualifier for more info.
    public abstract OrderDetails toEntity(final OrderResource resource, final String type);
                               ^

error: Can't map property "Map<String,Object> data" to "OrderDetails properties". Consider to declare/implement a mapping method: "OrderDetails map(Map<String,Object> value)".                            

I suspect that the additional parameter @Context final String type is not recognized but I don't know how to solve this.

0

There are 0 best solutions below