I have a model like
public class DeleteMe
{
[JsonProperty(PropertyName = "id")]
public string LalaId { get; set; }
public string Other { get; set; }
}
I want to be able to send a post request to an API action defined like
[HttpPost]
public async Task<IActionResult> Lala(DeleteMe requestPayload)
{
// do stuff
}
with the post body being
{
"id": "someID",
"other": "someOther"
}
However, when I make this request, the id
(LalaId) property isn't bound in the API action. If I send it as LalaId, then it works. But I want that property to be both sent to the client side and received from the client side as id
.
I'm using .net core 3.1. I know that with core 3, they've switched from Newtonsoft to their own JSON implementation, but in my Startup.cs I have added
services
.AddControllersWithViews()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new CustomJsonContractResolver();
options.SerializerSettings.Converters.Add(new DateTimeToTicksJsonConverter());
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
});
Which should force core to use Newtonsoft instead of System.Text.Json, right?
What is the issue here?
Thanks!