maliming
3 years ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
6 changed files with
25 additions and
33 deletions
-
framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo/Abp/AspNetCore/Mvc/NewtonsoftJson/AbpAspNetCoreMvcNewtonsoftModule.cs
-
framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpCamelCasePropertyNamesContractResolver.cs
-
framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDefaultContractResolver.cs
-
framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpJsonNewtonsoftModule.cs
-
framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpNewtonsoftJsonSerializer.cs
-
framework/src/Volo.Abp.Json.SystemTextJson/Volo/Abp/Json/SystemTextJson/AbpDefaultJsonTypeInfoResolver.cs
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using System; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Volo.Abp.Json.Newtonsoft; |
|
|
|
using Volo.Abp.Modularity; |
|
|
|
@ -13,9 +14,9 @@ public class AbpAspNetCoreMvcNewtonsoftModule : AbpModule |
|
|
|
context.Services.AddMvcCore().AddNewtonsoftJson(); |
|
|
|
|
|
|
|
context.Services.AddOptions<MvcNewtonsoftJsonOptions>() |
|
|
|
.Configure<AbpCamelCasePropertyNamesContractResolver>((options, contractResolver) => |
|
|
|
.Configure<IServiceProvider>((options, serviceProvider) => |
|
|
|
{ |
|
|
|
options.SerializerSettings.ContractResolver = contractResolver; |
|
|
|
options.SerializerSettings.ContractResolver = new AbpCamelCasePropertyNamesContractResolver(serviceProvider.GetRequiredService<AbpDateTimeConverter>()); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,22 +1,16 @@ |
|
|
|
using System; |
|
|
|
using System.Reflection; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using System.Reflection; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json.Serialization; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
|
|
|
|
namespace Volo.Abp.Json.Newtonsoft; |
|
|
|
|
|
|
|
public class AbpCamelCasePropertyNamesContractResolver : CamelCasePropertyNamesContractResolver, ITransientDependency |
|
|
|
public class AbpCamelCasePropertyNamesContractResolver : CamelCasePropertyNamesContractResolver |
|
|
|
{ |
|
|
|
private readonly Lazy<AbpDateTimeConverter> _dateTimeConverter; |
|
|
|
private readonly AbpDateTimeConverter _dateTimeConverter; |
|
|
|
|
|
|
|
public AbpCamelCasePropertyNamesContractResolver(IServiceProvider serviceProvider) |
|
|
|
public AbpCamelCasePropertyNamesContractResolver(AbpDateTimeConverter dateTimeConverter) |
|
|
|
{ |
|
|
|
_dateTimeConverter = new Lazy<AbpDateTimeConverter>( |
|
|
|
serviceProvider.GetRequiredService<AbpDateTimeConverter>, |
|
|
|
true |
|
|
|
); |
|
|
|
_dateTimeConverter = dateTimeConverter; |
|
|
|
|
|
|
|
NamingStrategy = new CamelCaseNamingStrategy |
|
|
|
{ |
|
|
|
@ -30,7 +24,7 @@ public class AbpCamelCasePropertyNamesContractResolver : CamelCasePropertyNamesC |
|
|
|
|
|
|
|
if (AbpDateTimeConverter.ShouldNormalize(member, property)) |
|
|
|
{ |
|
|
|
property.Converter = _dateTimeConverter.Value; |
|
|
|
property.Converter = _dateTimeConverter; |
|
|
|
} |
|
|
|
|
|
|
|
return property; |
|
|
|
|
|
|
|
@ -1,6 +1,4 @@ |
|
|
|
using System; |
|
|
|
using System.Reflection; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json.Serialization; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
@ -9,14 +7,11 @@ namespace Volo.Abp.Json.Newtonsoft; |
|
|
|
|
|
|
|
public class AbpDefaultContractResolver : DefaultContractResolver, ITransientDependency |
|
|
|
{ |
|
|
|
private readonly Lazy<AbpDateTimeConverter> _dateTimeConverter; |
|
|
|
private readonly AbpDateTimeConverter _dateTimeConverter; |
|
|
|
|
|
|
|
public AbpDefaultContractResolver(IServiceProvider serviceProvider) |
|
|
|
public AbpDefaultContractResolver(AbpDateTimeConverter dateTimeConverter) |
|
|
|
{ |
|
|
|
_dateTimeConverter = new Lazy<AbpDateTimeConverter>( |
|
|
|
serviceProvider.GetRequiredService<AbpDateTimeConverter>, |
|
|
|
true |
|
|
|
); |
|
|
|
_dateTimeConverter = dateTimeConverter; |
|
|
|
} |
|
|
|
|
|
|
|
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) |
|
|
|
@ -25,7 +20,7 @@ public class AbpDefaultContractResolver : DefaultContractResolver, ITransientDep |
|
|
|
|
|
|
|
if (AbpDateTimeConverter.ShouldNormalize(member, property)) |
|
|
|
{ |
|
|
|
property.Converter = _dateTimeConverter.Value; |
|
|
|
property.Converter = _dateTimeConverter; |
|
|
|
} |
|
|
|
|
|
|
|
return property; |
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using System; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Volo.Abp.Modularity; |
|
|
|
using Volo.Abp.Timing; |
|
|
|
|
|
|
|
@ -10,9 +11,9 @@ public class AbpJsonNewtonsoftModule : AbpModule |
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
|
{ |
|
|
|
context.Services.AddOptions<AbpNewtonsoftJsonSerializerOptions>() |
|
|
|
.Configure<AbpCamelCasePropertyNamesContractResolver>((options, contractResolver) => |
|
|
|
.Configure<IServiceProvider>((options, serviceProvider) => |
|
|
|
{ |
|
|
|
options.JsonSerializerSettings.ContractResolver = contractResolver; |
|
|
|
options.JsonSerializerSettings.ContractResolver = new AbpCamelCasePropertyNamesContractResolver(serviceProvider.GetRequiredService<AbpDateTimeConverter>()); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -34,7 +34,7 @@ public class AbpNewtonsoftJsonSerializer : IJsonSerializer, ITransientDependency |
|
|
|
return JsonConvert.DeserializeObject(jsonString, type, CreateJsonSerializerOptions(camelCase)); |
|
|
|
} |
|
|
|
|
|
|
|
private static readonly ConcurrentDictionary<object, JsonSerializerSettings> JsonSerializerOptionsCache = |
|
|
|
private readonly static ConcurrentDictionary<object, JsonSerializerSettings> JsonSerializerOptionsCache = |
|
|
|
new ConcurrentDictionary<object, JsonSerializerSettings>(); |
|
|
|
|
|
|
|
protected virtual JsonSerializerSettings CreateJsonSerializerOptions(bool camelCase = true, bool indented = false) |
|
|
|
@ -81,9 +81,11 @@ public class AbpNewtonsoftJsonSerializer : IJsonSerializer, ITransientDependency |
|
|
|
TypeNameAssemblyFormatHandling = Options.Value.JsonSerializerSettings.TypeNameAssemblyFormatHandling |
|
|
|
}; |
|
|
|
|
|
|
|
settings.ContractResolver = camelCase |
|
|
|
? ServiceProvider.GetRequiredService<AbpCamelCasePropertyNamesContractResolver>() |
|
|
|
: ServiceProvider.GetRequiredService<AbpDefaultContractResolver>(); |
|
|
|
if (!camelCase) |
|
|
|
{ |
|
|
|
// Default contract resolver is AbpCamelCasePropertyNamesContractResolver}
|
|
|
|
settings.ContractResolver = new AbpDefaultContractResolver(ServiceProvider.GetRequiredService<AbpDateTimeConverter>()); |
|
|
|
} |
|
|
|
|
|
|
|
if (indented) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -1,10 +1,9 @@ |
|
|
|
using System.Text.Json.Serialization.Metadata; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
|
|
|
|
namespace Volo.Abp.Json.SystemTextJson; |
|
|
|
|
|
|
|
public class AbpDefaultJsonTypeInfoResolver : DefaultJsonTypeInfoResolver, ITransientDependency |
|
|
|
public class AbpDefaultJsonTypeInfoResolver : DefaultJsonTypeInfoResolver |
|
|
|
{ |
|
|
|
public AbpDefaultJsonTypeInfoResolver(IOptions<AbpSystemTextJsonSerializerModifiersOptions> options) |
|
|
|
{ |
|
|
|
|