-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Compilation fails if property name is start (substring) of another property #525
Comments
I got the same issue, when I used const mapper = createMapper({
strategyInitializer: classes(),
namingConventions: new CamelCaseNamingConvention(), // <---
}); If you use export class ShippingFee {
@AutoMap() @Expose() perPallet?: number;
}
export class OrderDto {
...
@AutoMap() @Expose() shippingFee?: ShippingFee;
...
}
export class Order {
...
@AutoMap() @Expose() shippingFeePerPallet?: number;
...
} And now when you map an const orderDto = new OrderDto();
const shippingFee = new ShippingFee();
shippingFee.perPallet = 10;
orderDto.shippingFee = shippingFee;
console.log('orderDto', orderDto); // orderDto OrderDto { shippingFee: ShippingFee { perPallet: 10 } }
const order = mapper.map(orderDto, OrderDto, Order);
console.log('order', order); // order Order { shippingFeePerPallet: 10 } Without the const mapper = createMapper({
strategyInitializer: classes()
}); |
Thank you, @Balint98 , it works for me, too! Closing the issue. |
I don't know why this issue is closed, it's still a problem. Auto Flattening is a nice to have but shouldn't be mandatory. I have two models, one with properties named I think the Auto Flattening should have an option to opt out from it. |
Is there an existing issue for this?
Describe the issue
I faced a very strange bug (I think). I have two classes, OrderDto and Order. These classes have 2 properties (among others), of which one is a starting substring of the other: shippingFee and shippingFeePerPallet, both nullable numbers.
I have a mapping profile to map from the former to the latter. First, I didn't specify these in the mapping profile explicitely, but when I tried to build the project, it failed with the following error (at the addProfile function):
I narrowed down the problem to the shippingFee property. I tried adding both properties to the profile explicitely, as follows:
But it still doesn't work. The way I got it working is that I deleted shippingFee from both the profile and the OrderDto class (not a good solution, but it confirms the source of the issue). Another workaround was that I renamed shippingFee to shipiingFee (yes, with a typo) in both classes, in which case it magically worked.
The strange thing is, that other properties also have this kind of same-starting-substring, but they work without errors (like status and statusEn) - even the workaround has the same substring: shipiingFee and shippingFeePerPallet also start with "ship".
Models/DTOs/VMs
Mapping configuration
Steps to reproduce
Expected behavior
Should map the properties to their counterparts as expected.
Screenshots
No response
Minimum reproduction code
No response
Package
@automapper/core
@automapper/classes
@automapper/nestjs
@automapper/pojos
@automapper/mikro
@automapper/sequelize
Other package and its version
No response
AutoMapper version
8.7.6
Additional context
No response
The text was updated successfully, but these errors were encountered: