Yes, the wait is over.
I have heard it manytimes why MVC does not support Camel Case serialization. As workaround people used to use ServiceStack or Json.NET.
But as per recent announcement, MVC 1.0.0 now serializes JSON with camel case names by default.
How?
Before it was something like below:
public class Person
{
public int Id { get; set; }
public string FullName { get; set; }
}
Would serialize to:
{“Id”:1,”Name”:”Neel Bhatt”}
Now after changes, it would automatically convert it to camel case as below:
{“id”:1,”fullName”:”Neel Bhatt”} //// Not the first letter here
How to add in MVC?
Well MVC 1.0.0 gifts you this functionality within services.AddMvc()
And in case if You want the old PascalCase behavior then you just need to add below lines into your services.AddMvc() of startup.cs class:
services
.AddMvc()
.AddJsonOptions(options =>
options.SerializerSettings.ContractResolver = new DefaultContractResolver());
Please note that it is purely configurable and if you do not wish to use this then just write above line of code in startup.cs.
Happy coding!