Class LifecycleOverloadDeduplicateSelector
In the context of lifecycle callback method selection (such as @BeforeMapping or @AfterMapping), it is possible to have multiple overloaded methods whose parameter lists are structurally identical except for the specific types, where those types are related by inheritance (e.g., one parameter is a superclass or subclass of another).
This selector groups such methods by their effective parameter signature (ignoring differences only in type hierarchy), and, within each group, retains only the method whose parameter types have the closest inheritance distance to the actual invocation types. This ensures that, for each group of nearly identical overloads, only the most specific and appropriate method is selected.
Example (see Issue3849Test):
@AfterMapping
default void afterMapping(Parent source, @MappingTarget ParentDto target) { ... }
@AfterMapping
default void afterMapping(Parent source, @MappingTarget ChildDto target) { ... }
When mapping a Child to a ChildDto,
only the method with ChildDto is selected, even though both methods match by signature
except for the target type's inheritance relationship.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends Method>
List<SelectedMethod<T>> getMatchingMethods(List<SelectedMethod<T>> methods, SelectionContext context)
-
Constructor Details
-
LifecycleOverloadDeduplicateSelector
public LifecycleOverloadDeduplicateSelector()
-
-
Method Details
-
getMatchingMethods
public <T extends Method> List<SelectedMethod<T>> getMatchingMethods(List<SelectedMethod<T>> methods, SelectionContext context)
-