I'd like deserialization to fail for the following model:
class ExampleModel
{
public ExampleEnum ExampleEnum { get; set; }
public string ExampleString { get; set; }
}
enum ExampleEnum
{
Value1,
Value2,
}
when the ExampleEnum
's value is not explicitly specified, i.e.:
{
"ExampleString " : "abc"
}
It seems that it falls back to the default enum's value by, well, default:
string json = "{ \"exampleString\" : \"abc\" }";
var model = JsonSerializer.Deserialize<ExampleModel>(json);
Console.WriteLine(model.ExampleEnum); // outputs "Value1"
Is it possible to change the behavior?