Merge pull request #6363 from JamesNK/patch-1

Return a shared contract resolver
This commit is contained in:
Eilon Lipton 2017-06-07 14:37:18 -07:00 committed by GitHub
commit 32e21e2a5c
1 changed files with 9 additions and 5 deletions

View File

@ -13,6 +13,13 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
{ {
private const int DefaultMaxDepth = 32; private const int DefaultMaxDepth = 32;
// return shared resolver by default for perf so slow reflection logic is cached once
// developers can set their own resolver after the settings are returned if desired
private static readonly DefaultContractResolver SharedContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy(),
};
/// <summary> /// <summary>
/// Creates default <see cref="JsonSerializerSettings"/>. /// Creates default <see cref="JsonSerializerSettings"/>.
/// </summary> /// </summary>
@ -21,10 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
{ {
return new JsonSerializerSettings return new JsonSerializerSettings
{ {
ContractResolver = new DefaultContractResolver ContractResolver = SharedContractResolver,
{
NamingStrategy = new CamelCaseNamingStrategy(),
},
MissingMemberHandling = MissingMemberHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore,
@ -38,4 +42,4 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
}; };
} }
} }
} }