Open dougbu opened 8 years ago
In previous milestones, MVC's JSON serialization used Json.NET's default naming convention. This maintained C# property names in the JSON.
In 1.0.0, MVC uses camel case names by default. This matches most JSON naming conventions.
Applications which depend on the exact bytes sent over the wire or that include code such as
dynamic d = JObject.Parse(body);
may need to be adjusted.
If you have case-sensitive clients that cannot be easily updated, change your Startup from
Startup
services.AddMvc();
to
services .AddMvc() .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
public class Person { public int Id { get; set; } public string FullName { get; set; } }
Would serialize to
{"Id":9000,"FullName":"John Smith"}
The same model will serialize to
{"id":9000,"fullName":"John Smith"}
Note the initial lowercase letters.
Please see aspnet/Mvc#4842 for discussion of this change.
See also the original issue we fixed in 1.0.0: aspnet/Mvc#4283
Updated description to show the configuration one-liner.
In previous milestones, MVC's JSON serialization used Json.NET's default naming convention. This maintained C# property names in the JSON.
In 1.0.0, MVC uses camel case names by default. This matches most JSON naming conventions.
Potential compatibility breaks
Applications which depend on the exact bytes sent over the wire or that include code such as
may need to be adjusted.
To restore previous naming strategy
If you have case-sensitive clients that cannot be easily updated, change your
Startup
fromto
Example
Before
Would serialize to
After
The same model will serialize to
Note the initial lowercase letters.