-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.2" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
using Scaffolding.Json.Newtonsoft; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class ServiceCollectionServiceExtensions | ||
{ | ||
public static IServiceCollection ConfigureJsonNewtonsoft(this IServiceCollection services, NamingStrategy namingStrategy, Action<MvcNewtonsoftJsonOptions> configureOptions = null) | ||
Check warning on line 13 in src/Scaffolding.Json.Newtonsoft/ServiceCollectionServiceExtensions.cs GitHub Actions / build
Check warning on line 13 in src/Scaffolding.Json.Newtonsoft/ServiceCollectionServiceExtensions.cs GitHub Actions / build
Check warning on line 13 in src/Scaffolding.Json.Newtonsoft/ServiceCollectionServiceExtensions.cs GitHub Actions / deploy
Check warning on line 13 in src/Scaffolding.Json.Newtonsoft/ServiceCollectionServiceExtensions.cs GitHub Actions / deploy
Check warning on line 13 in src/Scaffolding.Json.Newtonsoft/ServiceCollectionServiceExtensions.cs GitHub Actions / deploy
|
||
{ | ||
ScaffoldingJsonNamingStrategy.DEFAULT_STRATEGY = namingStrategy; | ||
services.AddControllers().AddNewtonsoftJson(x => | ||
{ | ||
x.SerializerSettings.ContractResolver = new DefaultContractResolver() { NamingStrategy = ScaffoldingJsonNamingStrategy.DEFAULT_STRATEGY }; | ||
x.SerializerSettings.Converters.Add(new StringEnumConverter(ScaffoldingJsonNamingStrategy.GET_DEFAULT_STRATEGY_TYPE)); | ||
x.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; | ||
configureOptions?.Invoke(x); | ||
}); | ||
return services; | ||
} | ||
} | ||
} |