I have an object defined as such
public class FilingSearchCriteria
{
public int? FilerId { get; set; }
public int? TypeId { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public bool? Legacy { get; set; }
public bool? NoAtttachments { get; set; }
public bool? MissingFields { get; set; }
public bool? MissingAttachments { get; set; }
public string DocketNumber { get; set; }
}
A Net Core controller function takes it as a parameter.
[Route("api/[controller]/[action]")]
public class SearchController : ControllerBase
{
[HttpPost]
public async Task<IEnumerable<Domain.Filing.Filing>> Filings(FilingSearchCriteria crit) => //stuff
}
Incoming request
POST http://localhost:60680/api/search/filings/ HTTP/1.1
Host: localhost:60680
Connection: keep-alive
Content-Length: 77
sec-ch-ua: "Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36
Content-Type: application/json
Accept: application/json, text/plain, */*
Origin: http://localhost:4200
Sec-Fetch-Site: same-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://localhost:4200/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
{"EndDate":"2021-02-02T18:37:50.237Z","StartDate":"2021-01-26T18:37:50.237Z"}
Relevant Startup.cs code
services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.PropertyNamingPolicy = null);
Issue is the crit
param in the function ends up having all it's parameters be null
. No errors.
In addition the exact same JSON serializes properly through manual usage of JsonSerializer.Deserialize
as per this fiddle https://dotnetfiddle.net/xJOiCG
To add to confusion this is the only part of the app where deserialization fails like that. Everywhere else things serialize and deserialize just fine.