10/10/2020 8:10:29 PM

Microsoft has stupidly hardcoded opinionated casing into JSON serialization in .NET Core. Why is this stupid? Because who the fuck is MSFT to tell me how I want a field to be serialized? My field name is UserName. MSFT changes it to userName. Now if I wanted it to be userName, I would have fucking made it userName. But I didn't. I wanted it to be UserName. But MSFT thinks they are smarter than you and therefore they insist on fuckin with your data. Now, maybe you are ok with MSFT fuckin with your data but I am not.

Fortunately, there is a rather simple fix (outside of dropping MSFT). You can make the following change in your Startup.cs file.

public void ConfigureServices(IServiceCollection services) { ... services.AddControllers().AddJsonOptions(jsonOptions => { jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null; }); //or if you are using controllers and views services.AddControllersWithViews().AddJsonOptions(jsonOptions => { jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null; }); ... }