I have an ASP.NET Web API on .NET Core 3.1 using the Microsoft.AspNetCore.OData package to implement several OData controllers. One of the models has a string field used to hold HTML, and I am using the model in the request body for one of the OData endpoints. Because the string content is HTML, it must contain double quotes which I am escaping in the JSON body. However, when the request body is converted into the model, it doesn't recognize that the string is already escaped and actually escapes the escape characters. The issue is reproduced in a GitHub repository here.
Model:
public class Model
{
public int Id { get; set; }
public string Html { get; set; }
}
Request body:
{
"html": "<div class=\"test\"><\/div>"
}
Expected
Html == "<div class=\"test\"></div>"
Actual
Html == "<div class=\\\"test\\\"></div>"
Why is it doing this and how can I fix it?