I have simple controller with custom model type Heading - without parameterless constructor and public setter.
I tried following code in asp.net mvc core 2.2 and 3.1.
Model class:
public class Heading
{
public string Title { get; }
public Heading(string title)
{
Title = title;
}
}
API Controller:
[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
[HttpPost]
public void Post([FromBody] Heading value)
{
}
}
With .net core 2.2, binding works perfectly. But for core 3.1, it throws error
System.NotSupportedException: Deserialization of reference types without parameterless constructor is not supported. Type 'WebApplication3.Controllers.Heading' at System.Text.Json.ThrowHelper.ThrowNotSupportedException_DeserializeCreateObjectDelegateIsNull(Type invalidType)
Is this change in behaviour? Can it still be achieved?