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):
.../server/node_modules/@automapper/core/index.cjs:1092
return Object.prototype.hasOwnProperty.call(obj, property);
^
[2022.12.19 10:44:47] [error] - TypeError: Cannot convert undefined or null to object
[...]
at addProfile (.../server/node_modules/@automapper/core/index.cjs:1373:11)
I narrowed down the problem to the shippingFee property. I tried adding both properties to the profile explicitely, as follows:
createMap(
mapper,
OrderDto,
Order,
forMember(
(dest) => dest.shippingFee,
mapFrom((source) => source.shippingFee)
),
forMember(
(dest) => dest.shippingFeePerPallet,
mapFrom((source) => source.shippingFeePerPallet)
)
);
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
export class OrderDto {
...
@AutoMap() @Expose() shippingFee?: number;
@AutoMap() @Expose() shippingFeePerPallet?: number;
...
}
export class Order {
...
@AutoMap() @Expose() shippingFee?: number;
@AutoMap() @Expose() shippingFeePerPallet?: number;
...
}
Mapping configuration
createMap(
mapper,
OrderDto,
Order,
forMember(
(dest) => dest.shippingFee,
mapFrom((source) => source.shippingFee)
),
forMember(
(dest) => dest.shippingFeePerPallet,
mapFrom((source) => source.shippingFeePerPallet)
)
);
Steps to reproduce
- Implement the following classes and mapping
- Add the profile
- Try to build
Expected behavior
Should map the properties to their counterparts as expected.
Screenshots
No response
Minimum reproduction code
No response
Package
Other package and its version
No response
AutoMapper version
8.7.6
Additional context
No response
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/sequelizeOther package and its version
No response
AutoMapper version
8.7.6
Additional context
No response