Witam ! Pracuję z MapStruct i potrzebuję zmapować AssetPrototype i zrobić custom metodę zwracającą pole Attachment... Wszystko byłoby git, gdyby jeżeli Mapper pobierał w argumentach custom metody sam obiekt AssetPrototype, a nie tylko Attachment bo tak, używam tylko i wyłącznie obiekt Attachment, jakoś operuję tylko w jednym miejscu potrzeubuje id, asstetPrototype, w którym się znajduje Attachment, dlatego wali error.
Jak widać w ostatniej metodzie dostaję id z obiekta AssetPrototype, właśnie dlatego wali error, bo w argumentach musi się znajdować Attachment, a nie AssetProperty Jak można to rozwiązać?
@Mapper(componentModel = "spring")
public abstract class AssetPrototypeMapper {
@Autowired
protected AssetPropertiesFactory propertiesFactory;
@Autowired
protected FilesStore filesStore;
@Autowired
protected UUIDGenerator generator;
...
...
@Mapping(source = "attachments", target = "attachable", qualifiedByName = "customAttachments")
public abstract AssetPrototype toEntity(AssetPrototypeDocument document)
...
...
protected BaseAttachable customAttachments(Attachment attachment) {
}
@Named("customAttachments")
protected BaseAttachable customAttachments(AssetPrototypeDocument document) {
return new BaseAttachable(filesStore,
document.attachments == null ? new ArrayList<>() : document.attachments,
"assetsPrototypes/" + document.id + "/attachments/", generator);
}
...
...
}