Hello :)
I noticed that the json Format in ASP.NET Boilerplate is camelCase. How to force it to be PascalCase? Do i have to write my Formatter or?
Tnx :)
5 Answer(s)
-
0
Hi,
A solution is mentioned here <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/769">https://github.com/aspnetboilerplate/as ... issues/769</a>. You can also change ContractResolver in your WebApiModule's initialize method like this.
Configuration.Modules.AbpWebApi().HttpConfiguration.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new DefaultContractResolver();
-
0
Hi ismcagdas,,
I add following following code
Configuration.Modules.AbpWebApi().HttpConfiguration.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new DefaultContractResolver();
in WebApiModel.Initialize, and the return response still camelCase, not pascalCase.
Then I write a customerContractResolver for pascalCase, still not work
public class PascalCasePropertyNamesContractResolver : DefaultContractResolver { public new static readonly PascalCasePropertyNamesContractResolver Instance = new PascalCasePropertyNamesContractResolver(); protected override string ResolvePropertyName(string propertyName) { return propertyName.ToPascalCase(); } }
Configuration.Modules.AbpWebApi().HttpConfiguration.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new PascalCasePropertyNamesContractResolver();
Do you know What am i missing?
BTW, my abp version is 1.2.0.0
-
0
Hi,
Can you try to move it to PostInitialize.
-
0
Thanks so much! Move following code to PostInitialize, now it works fine. Configuration.Modules.AbpWebApi().HttpConfiguration.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new DefaultContractResolver();
-
0
Great :)