Is that possible that the mapper can base on the source type to map?
See original GitHub issueI used AutoMapper (and mediatr which is also developed by Jimmy Bogard) in dotnet core before. It’s pretty nice that see it again in typescript.
However, the code base currently use the destination class to found out the source class is pretty strange.
Thats mean if we have two different source class to project to same vm model will get wrong.
Here is the example that
class User {
@Expose()
firstName!: string;
@Expose()
lastName!: string;
@ExposedType(() => Profile)
profile!: Profile;
}
class User2 {
@Expose()
firstName!: string;
@Expose()
lastName!: string;
@ExposedType(() => Profile)
profile!: Profile;
}
mapper
.createMap(User, UserVm)
.forMember(d => d.first, opts => opts.mapFrom(s => "Khang"))
.forMember(d => d.last, opts => opts.mapFrom(s => s.lastName))
.forMember(
d => d.full,
opts => opts.mapFrom(s => s.firstName + " " + s.lastName)
);
mapper
.createMap(User2, UserVm)
.forMember(d => d.first, opts => opts.fromValue("a"))
.forMember(d => d.last, opts => opts.fromValue("B"))
.forMember(
d => d.full,
opts => opts.mapFrom(s => s.firstName + " " + s.lastName)
);
Now if we project a User2 obj to UserVm it will still keep using the first mapping
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to map from base type of object? - Stack Overflow
that I want to map between where in both Source and Destination the property Data is some type for which there exists a...
Read more >One-Stop Guide to Mapping with MapStruct - Reflectoring
Mapper Definition. We will now take a look into various types of bean mappers using MapStruct and try out whatever options are available....
Read more >Mapper Type - Apache Ant
This mapper implementation can contain multiple nested mappers. File mapping is performed by passing the source filename to the first nested mapper, its...
Read more >Using Multiple Source Objects with MapStruct - Baeldung
Learn how to use multiple source objects with MapStruct. ... We can now define a mapper that maps a Customer object to a...
Read more >MapStruct 1.5.3.Final Reference Guide
MapStruct takes all public properties of the source and target types into account. This includes properties declared on super-types. 3.2.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@vip30
nestjsx-automapper
2.0.7 has been released.It works as expected and will wait for your release on
nestjsx-automapper
Thanks you