I've had a good google but can't seem to find a replacement for Json.Net's annotations in System.Text.Json (specifically JsonRequired).
Is the new Microsoft framework not really a replacement for Newtonsoft?
I've had a good google but can't seem to find a replacement for Json.Net's annotations in System.Text.Json (specifically JsonRequired).
Is the new Microsoft framework not really a replacement for Newtonsoft?
Please try this library I wrote as an extension to System.Text.Json to offer missing features: https://github.com/dahomey-technologies/Dahomey.Json.
You will find support for JsonRequiredAttribute.
public class A
{
[JsonRequired]
public int Id { get;set; }
}
Setup json extensions by calling on JsonSerializerOptions the extension method SetupExtensions defined in the namespace Dahomey.Json. Then deserialize your class with the regular Sytem.Text.Json API.
JsonSerializerOptions options = new JsonSerializerOptions();
options.SetupExtensions();
const string json = @"{""Id"":12}";
A obj = JsonSerializer.Deserialize<A>(json, options);