-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
Cannot map Value
or HasValue
Property of Nullable<T>
#571
Comments
Thanks for the bug report, I'll look into it. |
Here's a repro: [Mapper(PropertyNameMappingStrategy = PropertyNameMappingStrategy.CaseInsensitive)]
public class MapperClass
{
public static partial Car MapCar(CarDto input);
public static partial CarDto MapCar(Car input);
}
public record CarDto()
{
public JsonElement? Amendment { get; set; }
}
public record Car()
{
[JsonIgnore, System.Runtime.Serialization.IgnoreDataMember]
public OtherThing? AmendmentMetadata
{
get => Amendment?.Deserialize<OtherThing>(JsonExtensions.JsonOptions);
}
[JsonIgnore, System.Runtime.Serialization.DataMember]
public string? AmendmentValue
{
get => Amendment?.GetRawText();
set => Amendment = value != null ? JsonSerializer.Deserialize<JsonElement>(value) : null;
}
[JsonInclude, System.Runtime.Serialization.IgnoreDataMember]
public JsonElement? Amendment { get; set; }
}
public class OtherThing
{
public string? Value { get; set; }
} |
Away rn, but I'm guessing because |
@TimothyMakkison I think its because of the If you rename |
Yeah I've updated my comment with more speculation. I'm guessing it only affects nullable value types because its an actual type. |
@TimothyMakkison maybe it was just doing a |
It's strange this issue didn't crop up when field mapping was introduced. |
One bug which I just found but also existed in v2.8.0 is that a nested nullable struct's flattened values cannot be resolved. I created another issue #572 since I'm not sure if it is related to this issue. |
I don't think #555 caused it I've been using the following [Fact]
public void VaueTest()
{
var source = TestSourceBuilder.MapperWithBodyAndTypes(
"partial B Map(A src);",
"public record A(int? P);",
"public record B { public int PValue { get; set; } }"
);
TestHelper
.GenerateMapper(source)
.Should()
.HaveSingleMethodBody(
"""
var target = new global::B();
if (src.P != null)
{
target.PValue = src.P.Value.Value;
}
return target;
"""
);
} |
@TimothyMakkison The test you provided, which should reproduce the bug described by OP, fails on v2.8.0. So this probably exists since a longer time and isn't a regression of |
The test passes when the bug occurs. Does this mean the bug doesn't happen with 2.8? |
@TimothyMakkison sorry my bad, I adjusted the test to verify that the bug does not exist. If I use exact your version, it fails on |
Name of this issue makes no sense anymore, should we close as duplicate? |
Value
or HasValue
Property of Nullable<T>
I adjusted the title. I think this is a slightly different issue than #572. Here the name of the target property |
Rel. #98 |
Describe the bug
I upgraded from next-2 to next-3 and now I am receiving a build error
It looks like the generated code is calling
.Value
twice:The text was updated successfully, but these errors were encountered: