Add @Source
annotation to enable usage of mapping source object in qualifier methods
#3477
Labels
Milestone
Use case
In addition to #3323, it would also be beneficial to introduce something like the
@Source
annotation. This annotation should behave similarly to the@Context
annotation but utilize the mapping source parameter instead.One use-case for implementing this feature is to support the localization of entity attributes during the mapping process to DTOs. In such cases, localization keys are dynamic and are likely calculated based on entity IDs in combination with attribute names.
By combining the
@Source
annotation with a@SourcePropertyName
, we could create an elegant solution. Utilizing thequalifiedBy
method, we could map entities to DTOs while taking into account localized values.Generated Code
Let this be our entity:
Then, mapper could look like this:
And here is the qualifier method:
Note: this is just an illustration how it could be used.
Possible workarounds
No response
MapStruct Version
No response
The text was updated successfully, but these errors were encountered: