DestinationTransform.EmptyCollectionIfNull overrides explicit null mapping
Chưa có ai nhận issue này.
- #960 của @wyf027 — đã đóng, không merge
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Bắt đầu với phần đăng ký DestinationTransform.EmptyCollectionIfNull và trường hợp DestinationTransformTests được nêu trong issue, sau đó tái hiện hành vi bằng TypeAdapterConfig và các kiểu Foo/FooDto được cung cấp. Theo dõi thời điểm global destination transform chạy so với kết quả .Map(...) rõ ràng; hoàn tất khi test pass với foo.Strings vẫn là null.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
When DestinationTransform.EmptyCollectionIfNull is configured globally via config.Default, it still overrides explicitly defined mappings that return null.
This behavior is unexpected because explicit mappings (via .Map(...)) should take precedence over global/default transforms.
- Mapster version: 10.0.8-pre06
- .NET version: net10.0
class FooDto
{
public string[]? Strings { get; set; }
}
record Foo(string?[] Strings);
public class DestinationTransformTests
{
[Fact]
public void ExplicitNullMapping_ShouldNotBeOverridden_ByDefaultEmptyCollectionTransform()
{
// Configure
var config = new TypeAdapterConfig();
config.Default
.AddDestinationTransform(DestinationTransform.EmptyCollectionIfNull);
config.NewConfig<Foo, FooDto>()
.Map(d => d.Strings, _ => (string[]?)null);
// Arrange
var fooDto = new Foo([]);
// Act
var foo = fooDto.Adapt<FooDto>(config);
// Assert
foo.Strings.ShouldBeNull();
}
}
Expected behavior
The explicit mapping:
.Map(d => d.Strings, _ => (string[]?)null)
should be respected, resulting in foo.Strings == null.
Actual behavior
foo.Strings is transformed into an empty array, meaning that EmptyCollectionIfNull is applied after the explicit mapping and overrides it.
Notes
The transform is registered on config.Default, not per-type.
This suggests that global destination transforms are applied at a stage where they override even explicit mapping results.
This makes it impossible to explicitly map a collection property to null when EmptyCollectionIfNull is enabled globally.
- Ngôn ngữ chính
- C#
- Star
- 5.2k
- Fork
- 409
- Merge trung bình
- 3 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của MapsterMapper/Mapster
-
.NET MatrixĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
MapsterMapper/Mapster#1003 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
MapsterMapper/Mapster#1024 · 1 bình luận ·
-
[Mapster Tool] Add support for global:: to disambiguate type names in generated mappersCó thể đã có người làm @DocSvartz đã nhận 1 ngày trước. Đang mởimprovement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
MapsterMapper/Mapster#1020 · 3 bình luận ·
-
Mapster.Tool - PropertySettingBuilder.Map(member, mapFunc, targetPropertyName) method is not working as expected!Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
MapsterMapper/Mapster#1017 · 6 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 57/100
MapsterMapper/Mapster#1007 · 5 bình luận ·
Tất cả issue của MapsterMapper/Mapster
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
gavin-wolfe/wolfden#104 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Still libmicrohttpd dependency is not removed properly from External-Dependency-Info.txt fileĐang mởtype/bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[辞書] かんそうりつ->乾燥率Đang mở辞書
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
thomhurst/TUnit#7201 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
ArduPilot/MissionPlanner#3826 ·
Maintainer thường phản hồi trong vòng 1 ngày