GeezerVison is showing github.com — Add `@SourcePropertyName` to handle a property name of the source object · Issue #3323 · mapstruct/mapstruct
Add @SourcePropertyName to handle a property name of the source object #3323Activityfiliphr commented on Jul 9, 2023 We might actually need a new @SourcePropertyName to have the source property. Currently all our tests use implicit mapping, and in this case the source and target property names are identical. filiphr commented on Oct 2, 2023 Discussed with the team we are going to add @SourcePropertyName that would pass the name of the source property and @TargetPropertyName that would pass the target property name aboqasem commented on Oct 7, 2023 Hello @filiphr & @babyfish-ct, I do not see where's the confusion in the name. It's indeed getting the target's property name as the name says. I added a test case that proves that: aboqasem@76e7067.
Am I missing something? thunderhook commented on Oct 7, 2023 @aboqasem I looked at the tests and the code and yes, indeed. The @TargetPropertyName handles the targets property name. So there will be an additional @SourcePropertyName annotation which handles the sources property name. I will rename this ticket to avoid any further confusion. changed the title [-]Rename `@TargetPropertyName` to `@PropertyName`[/-] [+]Add `@SourcePropertyName` to handle a property name of the source object[/+] on Oct 7, 2023aboqasem commented on Oct 7, 2023 Thank you @thunderhook!
This is my first time contributing to MapStruct. May I try to contribute to implementing this?
I started doing it and currently trying to understand what are the .ftl files (seems like they are for code gen). Then perhaps start with the org.mapstruct.ap.MappingProcessor class?
Any tips or pointers would help! thunderhook commented on Oct 12, 2023 What I would do in your case: Take a look at the commit where the @TargetPropertyName was introduced to see out how it works. I think the code for the @SourcePropertyName will be very similar.
Yes, the .ftl files are Apache FreeMarker java templates which are used for the code generation of mappers (and all of their belongings). The org.mapstruct.ap.internal.processor.MapperCreationProcessor is the main processor that handles the creation of a mapper class.
Another hint: When you run a test, e.g. the TargetPropertyNameTest, you can have a look at the generated sources and mappers that are generated and compiled in: ...\mapstruct\processor\target\compilation-tests\org.mapstruct.ap.test.conditional.targetpropertyname.TargetPropertyNameTest.
If it is okay with @filiphr (I don't know if he's currently working on this issue) you are welcome to contribute! Reacted by Mohammad Al Zouabi aboqasem commented on Oct 14, 2023 Thanks a lot, @thunderhook!
I was looking for the generated classes in the wrong place, thanks for the hint!
Let me try to check the good-first-issues first, since there's 5 of them at the moment. markostijak commented on Dec 6, 2023 Can we have something like @Source annotation as well, together with @SourcePropertyName.
@Source should behave similar to the @Context annotation, but use mapping source parameter instead.
My usecase is a localization, where localization keys are calculated based on entity ids and attribute names. filiphr commented on Dec 15, 2023 That makes sense @markostijak. That you are asking might be more in the direction of #2559.
However, I would suggest to create a new issue for this, let's keep this issue only for @SourcePropertyName. Implementation wise it is really different added 2 commits that reference this issue on Jan 7, 2024#3323 Support access to the source property name #3323 Support access to the source property name added a commit that references this issue on Feb 11, 2024#3323 Support access to the source property name
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|