MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.3k stars 328 forks source link

Critical regression introduced in Mapster 7.3.0 when mapping to existing objects #537

Open andrerav opened 1 year ago

andrerav commented 1 year ago

There are numerous issues that have been reported since the release of 7.3.0 that seem to have a common theme -- performing a map to an existing object has a tendency to create a new object instance instead of preserving the instance being mapped. So far it seems that the following issues have reported this:

Other possibly related issues:

I'm working on investigating which chance in 7.3.0 that might have introduced this issue. I will update this issue when I have new information to share.

satano commented 1 year ago

Hello.

In this case, should not be version 7.3.0 marked as deprecated because of critical bugs in nuget.org?

doddgu commented 1 year ago

hi, is there any progress?

DocSvartz commented 11 months ago

Hello, new instanse always created if TDestination does not have a public constructor without parameters. Maybe this has something to do with the problem. In this case RecordTypeAdapter is selected for Class

Class is detected as Record in https://github.com/MapsterMapper/Mapster/blob/04ac871b55828c3909b6cee4764e6fab40db3983/src/Mapster/Utils/ReflectionUtils.cs#L161

andrerav commented 11 months ago

Thanks to @DocSvartz this issue has been partially fixed. See #634 for details.

DocSvartz commented 10 months ago

Hello @andrerav , have you had problems with dictionaries ? The generic KeyValuePair has always been detect as a record. when updating you always received new instanse KeyValuePair and include member if then has been detect as record new KeyValuePair<FakeRecordKey,FakeRecordValue> (New _Key, new _Value)

DocSvartz commented 10 months ago

@andrerav I open PR #646 When 2 Step of Fixing this problemm :)