Since ASP.NET Core 3.0 the default serializer is System.Text.Json which means that on most of the modern services an API such as this would not work:
[HttpPost("api/sms/delivery-reports")]
public IActionResult ReceiveDeliveryReport([FromBody] SmsDeliveryResult deliveryResult)
{
foreach (var result in deliveryResult.Results)
{
System.Diagnostics.Debug.WriteLine($"{result.MessageId} - {result.Status.Name}");
}
return Ok();
}
(from your example of using webhooks)
The issue is that the models are decorated only with WCF and Newtonsoft's attributes like [DataMember(Name = "results", EmitDefaultValue = false)] or [JsonConstructor]. When a user uses one of your models in their controllers ASP.NET will try to deserialize the JSON using System.Text.Json.JsonSerializer.Deserialize but will fail because the capitalization of properties is not the same as expected.
To solve this you should add attributes such as [JsonPropertyName] where you use DataMember
Since ASP.NET Core 3.0 the default serializer is System.Text.Json which means that on most of the modern services an API such as this would not work:
(from your example of using webhooks)
The issue is that the models are decorated only with WCF and Newtonsoft's attributes like
[DataMember(Name = "results", EmitDefaultValue = false)]
or[JsonConstructor]
. When a user uses one of your models in their controllers ASP.NET will try to deserialize the JSON using System.Text.Json.JsonSerializer.Deserialize but will fail because the capitalization of properties is not the same as expected. To solve this you should add attributes such as[JsonPropertyName]
where you useDataMember
I hope to have been useful :)