New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support generic declarations of source and target bean types #583
Comments
I've ran into this problem recently, and I imagine it isn't an easy one to fix as it has been unresolved for a while. As a quick-fix, what about introducing @Mapper
public interface IdMapper {
@Mapping(source = "id", target = "id", sourceType = Long.class)
Target toTarget(IdHoldingTo<Long> src);
@Mapping(source = "id", target = "id", targetType = Long.class)
IdHoldingTo<Long> toHolder(Target target);
} It requires extra parameters and isn't ideal, but if detecting the generic field types is tricky then it might be a quick win. WDYT? |
The type detection is one thing - but once "we" get #644 fixed, it should be almost no problem anymore... @sjaakd is working hard on the fix, and it's probably the most important bugfix that needs to be done for the upcoming Final. So we need some solution there anyway, for many usecases. The other thing that could turn out tricky is to check where in our code templates the generics-declaration might be missing... :) So I'd say let's wait out the fix for #644 and then we can revisit this issue - it shouldn't be too hard to do then anymore. |
Have this problem as well. I added generics to my BaseEntity class as some entity ids were of different types, such as
...results in this error message when running the
Not possible to declare a |
I also updated the
|
Oh, that seems to have fallen off the radar. I'd like to give it another look in the next weeks. |
Actually, my problem is not the same as mentioned above. I read issue #79, and it seems to already be supported. Sorry about that. This is the
|
https://stackoverflow.com/questions/32096886/mapstruct-mapping-of-generics Hey, is there any progress regarding that issue ? |
Any news on this one? We are having a very similar issue with mapping models using generics |
example of opening post seems to be working with 1.4.2.Final @Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2022-04-26T22:25:36+0200",
comments = "version: 1.4.2.Final, compiler: Eclipse JDT (IDE) 1.4.50.v20210914-1429, environment: Java 17.0.1 (Azul Systems, Inc.)"
)
public class IdMapperImpl implements IdMapper {
@Override
public Target toTarget(IdHoldingTo<Long> src) {
if ( src == null ) {
return null;
}
Target target = new Target();
target.setId( src.getId() );
return target;
}
@Override
public IdHoldingTo<Long> toHolder(Target target) {
if ( target == null ) {
return null;
}
IdHoldingTo<Long> idHoldingTo = new IdHoldingTo<Long>();
idHoldingTo.setId( target.getId() );
return idHoldingTo;
}
} |
Follow-up to #574.
The following doesn't work, because we currently don't resolve the real property-types against the generic declarations of top-level source or target types.
The text was updated successfully, but these errors were encountered: