Browse Source

Clarify collection mapping behavior in docs

Added a note explaining that Mapperly preserves null values for collection properties during mapping, unlike AutoMapper which maps them to empty collections.
pull/23724/head
maliming 9 months ago
parent
commit
a72b01ab20
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 2
      docs/en/framework/infrastructure/object-to-object-mapping.md

2
docs/en/framework/infrastructure/object-to-object-mapping.md

@ -337,6 +337,8 @@ var users = await _userRepository.GetListAsync(); // returns List<User>
var dtos = ObjectMapper.Map<List<User>, List<UserDto>>(users); // creates List<UserDto>
````
> When mapping a collection property, if the source value is null Mapperly will keep the destination value as null. This is different from AutoMapper, which will map the destination field to an empty collection.
### Nested Mapping
When working with nested object mapping, there's an important limitation to be aware of. If you have separate mappers for nested types like in the example below, the parent mapper (`SourceTypeToDestinationTypeMapper`) will not automatically use the nested mapper (`SourceNestedTypeToDestinationNestedTypeMapper`) to handle the mapping of nested properties. This means that configurations like the `MapperIgnoreTarget` attribute on the nested mapper will be ignored during the parent mapping operation.

Loading…
Cancel
Save