You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]SmsDeliveryResultdeliveryResult){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
I hope to have been useful :)
The text was updated successfully, but these errors were encountered:
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 :)
The text was updated successfully, but these errors were encountered: