Browse Source
Merge pull request #6111 from abpframework/maliming/json-options
Add UseHybridSerializer to AbpJsonOptions.
pull/6117/head
Halil İbrahim Kalkan
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
24 additions and
1 deletions
-
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/MvcCoreBuilderExtensions.cs
-
framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs
-
framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonOptions.cs
|
|
@ -8,6 +8,7 @@ using Microsoft.Extensions.Options; |
|
|
using System.Text.Encodings.Web; |
|
|
using System.Text.Encodings.Web; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.ObjectPool; |
|
|
using Microsoft.Extensions.ObjectPool; |
|
|
|
|
|
using Volo.Abp.Json; |
|
|
|
|
|
|
|
|
namespace Volo.Abp.AspNetCore.Mvc.Json |
|
|
namespace Volo.Abp.AspNetCore.Mvc.Json |
|
|
{ |
|
|
{ |
|
|
@ -15,6 +16,14 @@ namespace Volo.Abp.AspNetCore.Mvc.Json |
|
|
{ |
|
|
{ |
|
|
public static IMvcCoreBuilder AddAbpHybridJson(this IMvcCoreBuilder builder) |
|
|
public static IMvcCoreBuilder AddAbpHybridJson(this IMvcCoreBuilder builder) |
|
|
{ |
|
|
{ |
|
|
|
|
|
var abpJsonOptions = builder.Services.ExecutePreConfiguredActions<AbpJsonOptions>(); |
|
|
|
|
|
if (!abpJsonOptions.UseHybridSerializer) |
|
|
|
|
|
{ |
|
|
|
|
|
builder.Services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<MvcNewtonsoftJsonOptions>, AbpMvcNewtonsoftJsonOptionsSetup>()); |
|
|
|
|
|
builder.AddNewtonsoftJson(); |
|
|
|
|
|
return builder; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//SystemTextJsonInputFormatter
|
|
|
//SystemTextJsonInputFormatter
|
|
|
builder.Services.AddTransient(provider => |
|
|
builder.Services.AddTransient(provider => |
|
|
{ |
|
|
{ |
|
|
|
|
|
@ -19,7 +19,12 @@ namespace Volo.Abp.Json |
|
|
Configure<AbpJsonOptions>(options => |
|
|
Configure<AbpJsonOptions>(options => |
|
|
{ |
|
|
{ |
|
|
options.Providers.Add<AbpNewtonsoftJsonSerializerProvider>(); |
|
|
options.Providers.Add<AbpNewtonsoftJsonSerializerProvider>(); |
|
|
options.Providers.Add<AbpSystemTextJsonSerializerProvider>(); |
|
|
|
|
|
|
|
|
var abpJsonOptions = context.Services.ExecutePreConfiguredActions<AbpJsonOptions>(); |
|
|
|
|
|
if (abpJsonOptions.UseHybridSerializer) |
|
|
|
|
|
{ |
|
|
|
|
|
options.Providers.Add<AbpSystemTextJsonSerializerProvider>(); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
Configure<AbpNewtonsoftJsonSerializerOptions>(options => |
|
|
Configure<AbpNewtonsoftJsonSerializerOptions>(options => |
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
using Volo.Abp.Collections; |
|
|
using Volo.Abp.Collections; |
|
|
|
|
|
using Volo.Abp.Json.SystemTextJson; |
|
|
|
|
|
|
|
|
namespace Volo.Abp.Json |
|
|
namespace Volo.Abp.Json |
|
|
{ |
|
|
{ |
|
|
@ -9,11 +10,19 @@ namespace Volo.Abp.Json |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public string DefaultDateTimeFormat { get; set; } |
|
|
public string DefaultDateTimeFormat { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// It will try to use System.Json.Text to handle JSON if it can otherwise use Newtonsoft.
|
|
|
|
|
|
/// Affects both AbpJsonModule and AbpAspNetCoreMvcModule.
|
|
|
|
|
|
/// See <see cref="AbpSystemTextJsonUnsupportedTypeMatcher"/>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool UseHybridSerializer { get; set; } |
|
|
|
|
|
|
|
|
public ITypeList<IJsonSerializerProvider> Providers { get; } |
|
|
public ITypeList<IJsonSerializerProvider> Providers { get; } |
|
|
|
|
|
|
|
|
public AbpJsonOptions() |
|
|
public AbpJsonOptions() |
|
|
{ |
|
|
{ |
|
|
Providers = new TypeList<IJsonSerializerProvider>(); |
|
|
Providers = new TypeList<IJsonSerializerProvider>(); |
|
|
|
|
|
UseHybridSerializer = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|