-
Notifications
You must be signed in to change notification settings - Fork 20
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
Map objectId to object #52
Comments
Hi, @Mapper()
abstract class TargetMapper {
@Mapping(target: 'source2', source: mapSource2)
Target fromSource(Source source, Source2 source2);
}
Source2 mapSource2(Source source, Source2 source2) => source2; Would generate this mapper. class TargetMapperImpl extends TargetMapper {
TargetMapperImpl() : super();
@override
Target fromSource(Source source, Source2 source2) {
final target = Target(source.text1, mapSource2(source, source2));
return target;
}
} |
Hi, yes but no :) I tried this solution before posting the issue, but faced with some problems.
This is because of UserModel and Company both have identical fields names "id" (and "name"). |
Test to reproduce:
|
Yes, that's a usecase I didn't think about. Right now I can ignore certain fields, but not by their source param. class IdSource {
final num id;
IdSource(this.id);
}
class IdTarget1 {
final num id;
IdTarget1(this.id);
}
class IdTarget2 {
final num id;
IdTarget2(this.id);
}
@Mapper()
abstract class IdMapper {
@Mapping(target: 'idTarget2.id', ignore: true)
IdSource fromTarget(IdTarget1 idTarget1, IdTarget2 idTarget2);
} This way it would only map the id of IdTarget1. |
Question: How to realize this kind of mapping?
"Multiple sources" example is close to that, but not exactly.
The text was updated successfully, but these errors were encountered: