I'm pretty new to C# and ASP.NET. I have an API controller with this action method:
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Mautic.Webhook
{
[ApiController]
[Route("mautic/[controller]")]
public class WebhookController : ControllerBase
{
public WebhookController(ILogger<WebhookController> logger)
{
Logger = logger;
}
[HttpPost]
public ActionResult WebhookAction(WebhookRequest data)
{
Logger.LogInformation(ObjectDumper.Dump(data.LeadPostDelete));
return NoContent();
}
private ILogger<WebhookController> Logger { get; }
}
}
And have this definition of WebhookRequest:
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Mautic
{
public class ContactWebhookRequest
{
public int id { get; set; }
public string timestamp { get; set; }
}
public class WebhookRequest
{
[JsonProperty(PropertyName = "mautic.lead_post_delete")]
public List<ContactWebhookRequest> LeadPostDelete { get; set; }
public string timestamp { get; set; }
}
}
When I receive data in the controller I want it to deserialize to my class but I got null on LeadPostDelete property. Does ASP.NET understand the Newtonsoft JsonProperty attribute? Or do I need to migrate it to System.Text.Json?
Also migrating to System.Text.Json is enough or I will need to deserialize this by hand on my controller?
application/jsonand an example of request data can be found here: gist.github.com/dhilst/046227d3d0e9d05b055c92fcbec72ac7