Question Details

No question body available.

Tags

c# json json.net

Answers (1)

July 8, 2026 Score: -1 Rep: 104 Quality: Low Completeness: 80%

video = "This is a video label" is a C# call-site default, not a deserialization fallback. C# uses that value only when the caller omits the argument; in your debug session Json.NET is supplying "", so the constructor has no missing argument for C# to fill.

Put the JSON-specific defaulting in the constructor body:

public class MyClass
{
    private const string DefaultVideoLabel = "This is a video label";

public readonly string ID; public readonly string VideoLabel;

public MyClass(string id, string video = DefaultVideoLabel) { ID = id; VideoLabel = string.IsNullOrEmpty(video) ? DefaultVideoLabel : video; } }

With this code, both a missing value that arrives as null and the "" value you are seeing become the default label.

If "" is a valid explicit value in your JSON and only missing/null should use the default, change the assignment to:

VideoLabel = video ?? DefaultVideoLabel;

DefaultValueHandling.Populate does not fix this constructor-parameter case; it does not make Json.NET omit the video argument so that C#'s optional-parameter default is applied.