-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Use case
based on https://mapstruct.org/documentation/stable/reference/html/#passing-target-type, what if I don't need to inject anything? more context is at #3472
@Mapper(
mappingControl = DeepClone.class,
uses = GroupProxyFactory.class,
componentModel = ComponentModel.SPRING)
interface GroupCloner {
Group clone(Group source);
}public class GroupProxyFactory {
// I could be static
<T extends Group> T resolve(Group entity, @TargetType Class<T> clazz) {
var trackedClass =
TrackerProxyFactory.getTrackedClass(
clazz, GroupModifications.class, GroupChangeTrackingInvoker.class);
// obnoxious long, doesn't really matter implementation
return res;
}
}I wrote a class with a static function (not thinking to annotate the class), and noticed it wasn't being used (actually it's still not).
I'm not longer sure if I'm reporting a bug, or requesting a feature... maybe both. It feels like this should work, but the generated code isn't using the GroupProxyFactory.
What I was going to suggest though is that it doesn't really need to know how to inject GroupProxyFactory, I wouldn't consider it a Bean it's just a class that it could new itself; or find a static method on.
As it is, even as documented it doesn't seem to work...
Generated Code
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2023-12-18T13:09:06-0500",
comments = "version: 1.5.5.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-8.5.jar, environment: Java 11.0.21 (Eclipse Adoptium)"
)
@Component
class GroupClonerImpl implements GroupCloner {
@Override
public Group clone(Group source) {
if ( source == null ) {
return null;
}
Group group = new Group();should be
Group group = groupProxyFactory.resolve(source, Group.class);Honestly I'd be even happier with
Group group = groupProxyFactory.resolve(source);Possible workarounds
No response
MapStruct Version
1.5.5