Json.NET behaviour could be defined by attributes: either use default or just throw an exception if json payload does not contain required property.
Yet System.Text.Json serializer silently does nothing.
Having class:
public sealed class Foo
{
[Required]
public int Prop {get;set;} = 10;
}
and deserializing empty object:
JsonSerializer.Deserialize<Foo>("{}");
I simply get an instance of Foo with Prop=10.
I could not find any setting in JsonSerializerOptions to force it throw an exception. Is it possible?