Skip to content

Commit

Permalink
Fix UpperCamelCaseNamingStrategy (cannot use NewtonSoft.Json to set j…
Browse files Browse the repository at this point in the history
…son naming policy)
  • Loading branch information
eanzhao committed Jun 8, 2022
1 parent e7376fc commit a1098ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/AElf.WebApp.Web/UpperCamelCaseNamingStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Newtonsoft.Json.Serialization;
using System.Text.Json;

namespace AElf.WebApp.Web;

public class UpperCamelCaseNamingStrategy : CamelCaseNamingStrategy
public class UpperCamelCaseNamingStrategy : JsonNamingPolicy
{
protected override string ResolvePropertyName(string name)
public override string ConvertName(string name)
{
var result = base.ResolvePropertyName(name);
result = char.ToUpperInvariant(result[0]) + result.Substring(1);
var result = CamelCase.ConvertName(name);
result = char.ToUpperInvariant(result[0]) + result[1..];
return result;
}
}
15 changes: 5 additions & 10 deletions src/AElf.WebApp.Web/WebWebAppAElfModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Swashbuckle.AspNetCore.SwaggerGen;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
Expand Down Expand Up @@ -61,17 +60,13 @@ public override void ConfigureServices(ServiceConfigurationContext context)

ConfigureSwaggerServices(context.Services);

context.Services.AddControllers(options =>
context.Services.AddControllers(configure =>
{
options.InputFormatters.Add(new ProtobufInputFormatter());
options.OutputFormatters.Add(new ProtobufOutputFormatter());
}).AddNewtonsoftJson(options =>
configure.InputFormatters.Add(new ProtobufInputFormatter());
configure.OutputFormatters.Add(new ProtobufOutputFormatter());
}).AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver
{
NamingStrategy = new UpperCamelCaseNamingStrategy()
};
options.SerializerSettings.Converters.Add(new ProtoMessageConverter());
options.JsonSerializerOptions.PropertyNamingPolicy = new UpperCamelCaseNamingStrategy();
});

context.Services.AddAuthentication("BasicAuthentication")
Expand Down

0 comments on commit a1098ed

Please sign in to comment.