-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Default value for optional ctor params should be used when matching prop is ignored #60082
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsRepro: public class Point
{
public int X { get; }
[JsonIgnore]
public int Y { get; }
public Point(int x, int y = 5) => (X, Y) = (x, y);
}
string json = "{}";
var point = JsonSerializer.Deserialize<Point>(json);
Console.WriteLine(point.Y);
// Expected: 5
// Actual: 0 The behavior should be consistent with then the matching prop is not ignored: public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y = 5) => (X, Y) = (x, y);
}
string json = "{}";
var point = JsonSerializer.Deserialize<Point>(json);
Console.WriteLine(point.Y);
// Expected: 5
// Actual: 5
|
should we consider this for 6.0? it might lead to data loss |
Is this a regression from 5.0 behavior? |
No this behavior shipped in 5.0. A fix for this can be considered a breaking change. I recommend addressing early in 7.0 as a bug fix so we have time to react to any feedback. |
Repro:
The behavior should be consistent with then the matching prop is not ignored:
The text was updated successfully, but these errors were encountered: