So ASP.NET Core has been out for a few years. My Quid Android phone app is due for an upgrade, starting with the backend REST WebAPI. This is a great time to get started with ASP.NET Core.
Json serialization defaults to pascalCase
To assist with my new Android app, I created a Message project (using .NET Standard), which will be shared between my WebApi app and Android app, with application/json used as the HTTP format. All my message objects use PascalCase.
My initial test revealed the Json showing up in the client was converted to pascalCase. A little searching revealed a simple answer. The following code needed to be added to the ConfigureService
call in Startup.cs:
public void ConfigureServices(IServiceCollection services) { services.AddControllers() .AddJsonOptions(options => { options.JsonSerializerOptions.PropertyNamingPolicy = null; });
That's it. Pretty simple fix. Hardly worth a BLOG post. But as with many of my BLOG posts, this one isn't just here for others. It's also for my own reference later...