Created
March 14, 2016 13:14
-
-
Save nbellocam/147a7d47c7a90490798e to your computer and use it in GitHub Desktop.
Asp.net core: Configure MVC to use camelCase for json serializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddMvc().AddJsonOptions(options => | |
{ | |
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); | |
options.SerializerSettings.DefaultValueHandling = DefaultValueHandling.Include; | |
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; | |
}); |
Hi @ranouf,
Honestly, I'm not sure as I didn't use it yet, but maybe this can help you: https://stackoverflow.com/a/58392418.
Thanks,
Thanks for your fast answer :)
The solution is to use "AddNewtonsoftJson" instead of "AddJsonOptions", like this no need to change the rest of your code
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews().AddJsonOptions(opts => opts.JsonSerializerOptions.PropertyNamingPolicy = null);
}
Default in .netcore5 hadd is casePascal
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
SerializerSettings is not available anymore with .net core 3.0, it has been replaced by JsonSerializerOptions which doesnt have ContractResolver , do you know by what do I need to replace it?