diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln
index b646c5f9e6..27f68c5410 100644
--- a/framework/Volo.Abp.sln
+++ b/framework/Volo.Abp.sln
@@ -413,7 +413,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Json.Newtonsoft",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Json.SystemTextJson", "src\Volo.Abp.Json.SystemTextJson\Volo.Abp.Json.SystemTextJson.csproj", "{0AD06E14-CBFE-4551-8D18-9E921D8F2A87}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Json.Core", "src\Volo.Abp.Json.Core\Volo.Abp.Json.Core.csproj", "{08531C5D-0436-4721-986D-96446CF54316}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Json.Abstractions", "src\Volo.Abp.Json.Abstractions\Volo.Abp.Json.Abstractions.csproj", "{08531C5D-0436-4721-986D-96446CF54316}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.NewtonsoftJson", "src\Volo.Abp.AspNetCore.Mvc.NewtonsoftJson\Volo.Abp.AspNetCore.Mvc.NewtonsoftJson.csproj", "{0CFC9D4F-F12F-4B44-ABCF-AB4A0E9E85B2}"
EndProject
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson.csproj
index 83ac5bc666..026fb2f4d4 100644
--- a/framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson.csproj
+++ b/framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson.csproj
@@ -19,6 +19,7 @@
+
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo/Abp/AspNetCore/Mvc/NewtonsoftJson/AbpAspNetCoreMvcNewtonsoftModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo/Abp/AspNetCore/Mvc/NewtonsoftJson/AbpAspNetCoreMvcNewtonsoftModule.cs
index f195f98bf4..6e71fe7b5f 100644
--- a/framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo/Abp/AspNetCore/Mvc/NewtonsoftJson/AbpAspNetCoreMvcNewtonsoftModule.cs
+++ b/framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo/Abp/AspNetCore/Mvc/NewtonsoftJson/AbpAspNetCoreMvcNewtonsoftModule.cs
@@ -1,47 +1,21 @@
-using System;
-using System.Collections.Generic;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Formatters;
+using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.DependencyInjection.Extensions;
-using Microsoft.Extensions.ObjectPool;
-using Microsoft.Extensions.Options;
-using Newtonsoft.Json;
-using Volo.Abp.AspNetCore.Mvc.Json;
using Volo.Abp.Json.Newtonsoft;
using Volo.Abp.Modularity;
namespace Volo.Abp.AspNetCore.Mvc.NewtonsoftJson;
-[DependsOn(typeof(AbpAspNetCoreMvcModule))]
+[DependsOn(typeof(AbpJsonNewtonsoftModule), typeof(AbpAspNetCoreMvcModule))]
public class AbpAspNetCoreMvcNewtonsoftModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
- context.Services.TryAddSingleton();
-
- Configure(mvcOptions =>
- {
- mvcOptions.InputFormatters.RemoveType();
- mvcOptions.OutputFormatters.RemoveType();
- });
-
- Configure(formatterOptions =>
- {
- formatterOptions.TextInputFormatters.Add();
- formatterOptions.TextOutputFormatters.Add();
- });
+ context.Services.AddMvcCore().AddNewtonsoftJson();
context.Services.AddOptions()
- .Configure((options, serviceProvider) =>
+ .Configure((options, contractResolver) =>
{
- options.SerializerSettings.ContractResolver = serviceProvider.GetRequiredService();
-
- var converters = serviceProvider.GetRequiredService>().Value
- .Converters.Select(converterType => serviceProvider.GetRequiredService(converterType).As())
- .ToList();
-
- options.SerializerSettings.Converters.InsertRange(0, converters);
+ options.SerializerSettings.ContractResolver = contractResolver;
});
}
}
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo/Abp/AspNetCore/Mvc/NewtonsoftJson/AbpNewtonsoftJsonFormatter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo/Abp/AspNetCore/Mvc/NewtonsoftJson/AbpNewtonsoftJsonFormatter.cs
deleted file mode 100644
index aa411bfb61..0000000000
--- a/framework/src/Volo.Abp.AspNetCore.Mvc.NewtonsoftJson/Volo/Abp/AspNetCore/Mvc/NewtonsoftJson/AbpNewtonsoftJsonFormatter.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-using System;
-using System.Buffers;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Formatters;
-using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.ObjectPool;
-using Microsoft.Extensions.Options;
-using Volo.Abp.AspNetCore.Mvc.Json;
-using Volo.Abp.DependencyInjection;
-
-namespace Volo.Abp.AspNetCore.Mvc.NewtonsoftJson;
-
-public class AbpNewtonsoftJsonFormatter : IAbpHybridJsonInputFormatter, IAbpHybridJsonOutputFormatter, ITransientDependency
-{
- private readonly ILoggerFactory _loggerFactory;
- private readonly ArrayPool _charPool;
- private readonly ObjectPoolProvider _objectPoolProvider;
- private readonly IOptions _mvcOptions;
- private readonly IOptions _mvcNewtonsoftJsonOptions;
-
- public AbpNewtonsoftJsonFormatter(
- ILoggerFactory loggerFactory,
- ArrayPool charPool,
- ObjectPoolProvider objectPoolProvider,
- IOptions mvcOptions,
- IOptions mvcNewtonsoftJsonOptions)
- {
- _loggerFactory = loggerFactory;
- _charPool = charPool;
- _objectPoolProvider = objectPoolProvider;
- _mvcOptions = mvcOptions;
- _mvcNewtonsoftJsonOptions = mvcNewtonsoftJsonOptions;
- }
-
- Task IAbpHybridJsonInputFormatter.CanHandleAsync(Type type)
- {
- return Task.FromResult(true);
- }
-
- public Task GetTextInputFormatterAsync()
- {
- return Task.FromResult(new NewtonsoftJsonInputFormatter(
- _loggerFactory.CreateLogger(),
- _mvcNewtonsoftJsonOptions.Value.SerializerSettings,
- _charPool,
- _objectPoolProvider,
- _mvcOptions.Value,
- _mvcNewtonsoftJsonOptions.Value));
- }
-
- Task IAbpHybridJsonOutputFormatter.CanHandleAsync(Type type)
- {
- return Task.FromResult(true);
- }
-
- public Task GetTextOutputFormatterAsync()
- {
- return Task.FromResult(new NewtonsoftJsonOutputFormatter(
- _mvcNewtonsoftJsonOptions.Value.SerializerSettings,
- _charPool,
- _mvcOptions.Value,
- _mvcNewtonsoftJsonOptions.Value));
- }
-}
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs
index 22b919c91c..20922527bf 100644
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs
+++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs
@@ -38,6 +38,7 @@ using Volo.Abp.GlobalFeatures;
using Volo.Abp.Http.Modeling;
using Volo.Abp.Http.ProxyScripting.Generators.JQuery;
using Volo.Abp.Json;
+using Volo.Abp.Json.SystemTextJson;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.UI;
@@ -52,7 +53,8 @@ namespace Volo.Abp.AspNetCore.Mvc;
typeof(AbpAspNetCoreMvcContractsModule),
typeof(AbpUiNavigationModule),
typeof(AbpGlobalFeaturesModule),
- typeof(AbpDddApplicationModule)
+ typeof(AbpDddApplicationModule),
+ typeof(AbpJsonSystemTextJsonModule)
)]
public class AbpAspNetCoreMvcModule : AbpModule
{
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProviderOptions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProviderOptions.cs
index 2b9e231874..4dc4a9719a 100644
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProviderOptions.cs
+++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProviderOptions.cs
@@ -62,19 +62,12 @@ public class AspNetCoreApiDescriptionModelProviderOptions
{
if (apiParameterDescription.ModelMetadata is DefaultModelMetadata defaultModelMetadata)
{
- var jsonPropertyNameAttribute = (System.Text.Json.Serialization.JsonPropertyNameAttribute)
- defaultModelMetadata?.Attributes?.PropertyAttributes?.FirstOrDefault(x => x is System.Text.Json.Serialization.JsonPropertyNameAttribute);
+ var jsonPropertyNameAttribute = (JsonPropertyNameAttribute)
+ defaultModelMetadata?.Attributes?.PropertyAttributes?.FirstOrDefault(x => x is JsonPropertyNameAttribute);
if (jsonPropertyNameAttribute != null)
{
return jsonPropertyNameAttribute.Name;
}
-
- var jsonPropertyAttribute = (Newtonsoft.Json.JsonPropertyAttribute)
- defaultModelMetadata?.Attributes?.PropertyAttributes?.FirstOrDefault(x => x is Newtonsoft.Json.JsonPropertyAttribute);
- if (jsonPropertyAttribute != null)
- {
- return jsonPropertyAttribute.PropertyName;
- }
}
return null;
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonFormatterOptions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonFormatterOptions.cs
deleted file mode 100644
index 066ebe4413..0000000000
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonFormatterOptions.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using Microsoft.AspNetCore.Mvc.Formatters;
-using Volo.Abp.Collections;
-
-namespace Volo.Abp.AspNetCore.Mvc.Json;
-
-public class AbpHybridJsonFormatterOptions
-{
- public ITypeList TextInputFormatters { get; }
-
- public ITypeList TextOutputFormatters { get; }
-
- public AbpHybridJsonFormatterOptions()
- {
- TextInputFormatters = new TypeList();
- TextOutputFormatters = new TypeList();
- }
-}
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs
deleted file mode 100644
index 874508ac1f..0000000000
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System;
-using System.Text;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc.Formatters;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Options;
-
-namespace Volo.Abp.AspNetCore.Mvc.Json;
-
-public class AbpHybridJsonInputFormatter : TextInputFormatter, IInputFormatterExceptionPolicy
-{
- public AbpHybridJsonInputFormatter()
- {
- SupportedEncodings.Add(UTF8EncodingWithoutBOM);
- SupportedEncodings.Add(UTF16EncodingLittleEndian);
-
- SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationJson);
- SupportedMediaTypes.Add(MediaTypeHeaderValues.TextJson);
- SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationAnyJsonSyntax);
- }
-
- public async override Task ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
- {
- return await (await GetTextInputFormatterAsync(context)).ReadRequestBodyAsync(context, encoding);
- }
-
- protected virtual async Task GetTextInputFormatterAsync(InputFormatterContext context)
- {
- var options = context.HttpContext.RequestServices.GetRequiredService>().Value;
-
- foreach (var inputFormatterType in options.TextInputFormatters)
- {
- var inputFormatter = context.HttpContext.RequestServices.GetRequiredService(inputFormatterType).As();
- if (await inputFormatter.CanHandleAsync(context.ModelType))
- {
- return await inputFormatter.GetTextInputFormatterAsync();
- }
- }
-
- throw new AbpException($"The {nameof(AbpHybridJsonInputFormatter)} can't handle '{context.ModelType.GetFullNameWithAssemblyName()}'!");
- }
-
- public virtual InputFormatterExceptionPolicy ExceptionPolicy => InputFormatterExceptionPolicy.MalformedInputExceptions;
-}
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs
deleted file mode 100644
index 2960ff1635..0000000000
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using System;
-using System.Text;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc.Formatters;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Options;
-
-namespace Volo.Abp.AspNetCore.Mvc.Json;
-
-public class AbpHybridJsonOutputFormatter : TextOutputFormatter
-{
- public AbpHybridJsonOutputFormatter()
- {
- SupportedEncodings.Add(Encoding.UTF8);
- SupportedEncodings.Add(Encoding.Unicode);
-
- SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationJson);
- SupportedMediaTypes.Add(MediaTypeHeaderValues.TextJson);
- SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationAnyJsonSyntax);
- }
-
- public async override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
- {
- await (await GetTextInputFormatter(context)).WriteResponseBodyAsync(context, selectedEncoding);
- }
-
- protected virtual async Task GetTextInputFormatter(OutputFormatterWriteContext context)
- {
- var options = context.HttpContext.RequestServices.GetRequiredService>().Value;
-
- foreach (var outputFormatterType in options.TextOutputFormatters)
- {
- var outputFormatter = context.HttpContext.RequestServices.GetRequiredService(outputFormatterType).As();
- if (await outputFormatter.CanHandleAsync(context.ObjectType))
- {
- return await outputFormatter.GetTextOutputFormatterAsync();
- }
- }
-
- throw new AbpException($"The {nameof(AbpHybridJsonOutputFormatter)} can't handle '{context.ObjectType.GetFullNameWithAssemblyName()}'!");
- }
-}
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpSystemTextJsonFormatter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpSystemTextJsonFormatter.cs
deleted file mode 100644
index fb8c509748..0000000000
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpSystemTextJsonFormatter.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using System;
-using System.Text.Encodings.Web;
-using System.Text.Json;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Formatters;
-using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Options;
-using Volo.Abp.DependencyInjection;
-using Volo.Abp.Json.SystemTextJson;
-
-namespace Volo.Abp.AspNetCore.Mvc.Json;
-
-public class AbpSystemTextJsonFormatter : IAbpHybridJsonInputFormatter, IAbpHybridJsonOutputFormatter, ITransientDependency
-{
- private readonly IOptions _jsonOptions;
- private readonly IOptions _systemTextJsonSerializerOptions;
- private readonly ILoggerFactory _loggerFactory;
-
- public AbpSystemTextJsonFormatter(
- IOptions jsonOptions,
- IOptions systemTextJsonSerializerOptions,
- ILoggerFactory loggerFactory)
- {
- _jsonOptions = jsonOptions;
- _systemTextJsonSerializerOptions = systemTextJsonSerializerOptions;
- _loggerFactory = loggerFactory;
- }
-
- Task IAbpHybridJsonInputFormatter.CanHandleAsync(Type type)
- {
- return Task.FromResult(!_systemTextJsonSerializerOptions.Value.UnsupportedTypes.Contains(type));
- }
-
- public virtual Task GetTextInputFormatterAsync()
- {
- return Task.FromResult(new SystemTextJsonInputFormatter(
- _jsonOptions.Value,
- _loggerFactory.CreateLogger()));
- }
-
- Task IAbpHybridJsonOutputFormatter.CanHandleAsync(Type type)
- {
- return Task.FromResult(!_systemTextJsonSerializerOptions.Value.UnsupportedTypes.Contains(type));
- }
-
- public Task GetTextOutputFormatterAsync()
- {
- var jsonSerializerOptions = _jsonOptions.Value.JsonSerializerOptions;
- if (jsonSerializerOptions.Encoder is null)
- {
- // If the user hasn't explicitly configured the encoder, use the less strict encoder that does not encode all non-ASCII characters.
- jsonSerializerOptions = new JsonSerializerOptions(jsonSerializerOptions)
- {
- Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
- };
- }
-
- return Task.FromResult(new SystemTextJsonOutputFormatter(jsonSerializerOptions));
- }
-}
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/IAbpHybridJsonInputFormatter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/IAbpHybridJsonInputFormatter.cs
deleted file mode 100644
index 0a167e58d4..0000000000
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/IAbpHybridJsonInputFormatter.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc.Formatters;
-
-namespace Volo.Abp.AspNetCore.Mvc.Json;
-
-public interface IAbpHybridJsonInputFormatter
-{
- Task CanHandleAsync(Type type);
-
- Task GetTextInputFormatterAsync();
-}
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/IAbpHybridJsonOutputFormatter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/IAbpHybridJsonOutputFormatter.cs
deleted file mode 100644
index 06418b88d4..0000000000
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/IAbpHybridJsonOutputFormatter.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc.Formatters;
-
-namespace Volo.Abp.AspNetCore.Mvc.Json;
-
-public interface IAbpHybridJsonOutputFormatter
-{
- Task CanHandleAsync(Type type);
-
- Task GetTextOutputFormatterAsync();
-}
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/MediaTypeHeaderValues.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/MediaTypeHeaderValues.cs
deleted file mode 100644
index 23d039ef30..0000000000
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/MediaTypeHeaderValues.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Microsoft.Net.Http.Headers;
-
-namespace Volo.Abp.AspNetCore.Mvc.Json;
-
-///
-/// https://github.com/dotnet/aspnetcore/blob/master/src/Mvc/Mvc.NewtonsoftJson/src/MediaTypeHeaderValues.cs
-///
-internal static class MediaTypeHeaderValues
-{
- public static readonly MediaTypeHeaderValue ApplicationJson = MediaTypeHeaderValue.Parse("application/json").CopyAsReadOnly();
-
- public static readonly MediaTypeHeaderValue TextJson = MediaTypeHeaderValue.Parse("text/json").CopyAsReadOnly();
-
- public static readonly MediaTypeHeaderValue ApplicationAnyJsonSyntax = MediaTypeHeaderValue.Parse("application/*+json").CopyAsReadOnly();
-
- public static readonly MediaTypeHeaderValue ApplicationXml = MediaTypeHeaderValue.Parse("application/xml").CopyAsReadOnly();
-
- public static readonly MediaTypeHeaderValue TextXml = MediaTypeHeaderValue.Parse("text/xml").CopyAsReadOnly();
-
- public static readonly MediaTypeHeaderValue ApplicationAnyXmlSyntax = MediaTypeHeaderValue.Parse("application/*+xml").CopyAsReadOnly();
-}
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/MvcCoreBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/MvcCoreBuilderExtensions.cs
index ea3f5ea156..66af7b060c 100644
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/MvcCoreBuilderExtensions.cs
+++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/MvcCoreBuilderExtensions.cs
@@ -1,7 +1,6 @@
using System;
using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.Json.SystemTextJson;
@@ -13,21 +12,6 @@ public static class MvcCoreBuilderExtensions
{
public static IMvcCoreBuilder AddAbpHybridJson(this IMvcCoreBuilder builder)
{
- builder.Services.Configure(options =>
- {
- options.InputFormatters.RemoveType();
- options.InputFormatters.Add(new AbpHybridJsonInputFormatter());
-
- options.OutputFormatters.RemoveType();
- options.OutputFormatters.Add(new AbpHybridJsonOutputFormatter());
- });
-
- builder.Services.Configure(options =>
- {
- options.TextInputFormatters.Add();
- options.TextOutputFormatters.Add();
- });
-
builder.Services.AddOptions()
.Configure((options, serviceProvider) =>
{
diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingContractResolver.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingContractResolver.cs
deleted file mode 100644
index 77d1b7ddb9..0000000000
--- a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingContractResolver.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Serialization;
-
-namespace Volo.Abp.Auditing;
-
-public class AuditingContractResolver : CamelCasePropertyNamesContractResolver
-{
- private readonly List _ignoredTypes;
-
- public AuditingContractResolver(List ignoredTypes)
- {
- _ignoredTypes = ignoredTypes;
- }
-
- protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
- {
- var property = base.CreateProperty(member, memberSerialization);
-
- if (_ignoredTypes.Any(ignoredType => ignoredType.GetTypeInfo().IsAssignableFrom(property.PropertyType)))
- {
- property.ShouldSerialize = instance => false;
- return property;
- }
-
- if (member.DeclaringType != null && (member.DeclaringType.IsDefined(typeof(DisableAuditingAttribute)) || member.DeclaringType.IsDefined(typeof(JsonIgnoreAttribute))))
- {
- property.ShouldSerialize = instance => false;
- return property;
- }
-
- if (member.IsDefined(typeof(DisableAuditingAttribute)) || member.IsDefined(typeof(JsonIgnoreAttribute)))
- {
- property.ShouldSerialize = instance => false;
- }
-
- return property;
- }
-}
diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/JsonAuditSerializer.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/JsonAuditSerializer.cs
new file mode 100644
index 0000000000..9d8c4248e6
--- /dev/null
+++ b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/JsonAuditSerializer.cs
@@ -0,0 +1,78 @@
+using System.Collections.Concurrent;
+using System.Linq;
+using System.Reflection;
+using System.Text.Json;
+using System.Text.Json.Serialization.Metadata;
+using Microsoft.Extensions.Options;
+using Volo.Abp.DependencyInjection;
+
+namespace Volo.Abp.Auditing;
+
+public class JsonAuditSerializer : IAuditSerializer, ITransientDependency
+{
+ protected AbpAuditingOptions Options;
+
+ public JsonAuditSerializer(IOptions options)
+ {
+ Options = options.Value;
+ }
+
+ public string Serialize(object obj)
+ {
+ return JsonSerializer.Serialize(obj, CreateJsonSerializerOptions());
+ }
+
+ private static readonly ConcurrentDictionary JsonSerializerOptionsCache =
+ new ConcurrentDictionary();
+
+ protected virtual JsonSerializerOptions CreateJsonSerializerOptions()
+ {
+ return JsonSerializerOptionsCache.GetOrAdd(nameof(JsonAuditSerializer), _ =>
+ {
+ var settings = new JsonSerializerOptions()
+ {
+ PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
+ TypeInfoResolver = new DefaultJsonTypeInfoResolver()
+ {
+ Modifiers =
+ {
+ jsonTypeInfo =>
+ {
+ if (Options.IgnoredTypes.Any(ignoredType => ignoredType.IsAssignableFrom(jsonTypeInfo.Type)))
+ {
+ jsonTypeInfo.Properties.Clear();
+ }
+
+ if (jsonTypeInfo.Type.GetCustomAttributes(typeof(DisableAuditingAttribute), false).Any())
+ {
+ jsonTypeInfo.Properties.Clear();
+ }
+
+ foreach (var property in jsonTypeInfo.Properties)
+ {
+ if (Options.IgnoredTypes.Any(ignoredType => ignoredType.IsAssignableFrom(property.PropertyType)))
+ {
+ property.ShouldSerialize = (_, _) => false;
+ }
+
+ if (property.AttributeProvider != null &&
+ property.AttributeProvider.GetCustomAttributes(typeof(DisableAuditingAttribute), false).Any())
+ {
+ property.ShouldSerialize = (_, _) => false;
+ }
+
+ if (property.PropertyType.DeclaringType != null &&
+ property.PropertyType.DeclaringType.IsDefined(typeof(DisableAuditingAttribute)))
+ {
+ property.ShouldSerialize = (_, _) => false;
+ }
+ }
+ }
+ }
+ }
+ };
+
+ return settings;
+ });
+ }
+}
diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/JsonNetAuditSerializer.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/JsonNetAuditSerializer.cs
deleted file mode 100644
index d5df2b2644..0000000000
--- a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/JsonNetAuditSerializer.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-using Microsoft.Extensions.Options;
-using Newtonsoft.Json;
-using Volo.Abp.DependencyInjection;
-
-namespace Volo.Abp.Auditing;
-
-//TODO: Rename to JsonAuditSerializer
-public class JsonNetAuditSerializer : IAuditSerializer, ITransientDependency
-{
- protected AbpAuditingOptions Options;
-
- public JsonNetAuditSerializer(IOptions options)
- {
- Options = options.Value;
- }
-
- public string Serialize(object obj)
- {
- return JsonConvert.SerializeObject(obj, GetSharedJsonSerializerSettings());
- }
-
- private static readonly object SyncObj = new object();
- private static JsonSerializerSettings _sharedJsonSerializerSettings;
-
- private JsonSerializerSettings GetSharedJsonSerializerSettings()
- {
- if (_sharedJsonSerializerSettings == null)
- {
- lock (SyncObj)
- {
- if (_sharedJsonSerializerSettings == null)
- {
- _sharedJsonSerializerSettings = new JsonSerializerSettings
- {
- ContractResolver = new AuditingContractResolver(Options.IgnoredTypes)
- };
- }
- }
- }
-
- return _sharedJsonSerializerSettings;
- }
-}
diff --git a/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj b/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj
index 5c83874fa0..1688a4246f 100644
--- a/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj
+++ b/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj
@@ -30,5 +30,6 @@
+
diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs
index 7aba9ae849..28ab693ba1 100644
--- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs
+++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs
@@ -2,17 +2,14 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Cli.Commands;
using Volo.Abp.Cli.Http;
-using Volo.Abp.Cli.LIbs;
using Volo.Abp.Cli.ServiceProxying;
using Volo.Abp.Cli.ServiceProxying.Angular;
using Volo.Abp.Cli.ServiceProxying.CSharp;
using Volo.Abp.Cli.ServiceProxying.JavaScript;
using Volo.Abp.Domain;
using Volo.Abp.Http;
-using Volo.Abp.Http.ProxyScripting.Generators.JQuery;
using Volo.Abp.IdentityModel;
using Volo.Abp.Json;
-using Volo.Abp.Json.SystemTextJson;
using Volo.Abp.Minify;
using Volo.Abp.Modularity;
@@ -34,11 +31,6 @@ public class AbpCliCoreModule : AbpModule
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
- Configure(options =>
- {
- options.UnsupportedTypes.Add(typeof(ResourceMapping));
- });
-
Configure(options =>
{
options.Commands[HelpCommand.Name] = typeof(HelpCommand);
diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs
index 654feb117b..b925a4220c 100644
--- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs
+++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs
@@ -7,6 +7,7 @@ using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
+using Newtonsoft.Json;
using NuGet.Versioning;
using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection;
@@ -30,12 +31,9 @@ public class InstallLibsService : IInstallLibsService, ITransientDependency
public ILogger Logger { get; set; }
- private readonly IJsonSerializer _jsonSerializer;
-
- public InstallLibsService(IJsonSerializer jsonSerializer, NpmHelper npmHelper)
+ public InstallLibsService(NpmHelper npmHelper)
{
NpmHelper = npmHelper;
- _jsonSerializer = jsonSerializer;
}
public async Task InstallLibsAsync(string directory)
@@ -119,7 +117,7 @@ public class InstallLibsService : IInstallLibsService, ITransientDependency
{
return false;
}
-
+
using (var reader = File.OpenText(file))
{
return reader.ReadToEnd().Contains("Microsoft.NET.Sdk.Web");
@@ -145,7 +143,8 @@ public class InstallLibsService : IInstallLibsService, ITransientDependency
{
var mappingFileContent = await reader.ReadToEndAsync();
- var mapping = _jsonSerializer.Deserialize(mappingFileContent
+ // System.Text.Json doesn't support the property name without quotes.
+ var mapping = Newtonsoft.Json.JsonConvert.DeserializeObject(mappingFileContent
.Replace("module.exports", string.Empty)
.Replace("=", string.Empty).Trim().TrimEnd(';'));
diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Configuration/AbpApiProxyScriptingConfiguration.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Configuration/AbpApiProxyScriptingConfiguration.cs
index e8da5693f6..86449c8971 100644
--- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Configuration/AbpApiProxyScriptingConfiguration.cs
+++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Configuration/AbpApiProxyScriptingConfiguration.cs
@@ -10,22 +10,6 @@ public static class AbpApiProxyScriptingConfiguration
static AbpApiProxyScriptingConfiguration()
{
PropertyNameGenerator = propertyInfo =>
- {
- var jsonPropertyNameAttribute = propertyInfo.GetSingleAttributeOrNull(true);
-
- if (jsonPropertyNameAttribute != null)
- {
- return jsonPropertyNameAttribute.Name;
- }
-
- var jsonPropertyAttribute = propertyInfo.GetSingleAttributeOrNull(true);
-
- if (jsonPropertyAttribute != null)
- {
- return jsonPropertyAttribute.PropertyName;
- }
-
- return null;
- };
+ propertyInfo.GetSingleAttributeOrNull()?.Name;
}
}
diff --git a/framework/src/Volo.Abp.Json.Core/FodyWeavers.xml b/framework/src/Volo.Abp.Json.Abstractions/FodyWeavers.xml
similarity index 100%
rename from framework/src/Volo.Abp.Json.Core/FodyWeavers.xml
rename to framework/src/Volo.Abp.Json.Abstractions/FodyWeavers.xml
diff --git a/framework/src/Volo.Abp.Json.Core/FodyWeavers.xsd b/framework/src/Volo.Abp.Json.Abstractions/FodyWeavers.xsd
similarity index 100%
rename from framework/src/Volo.Abp.Json.Core/FodyWeavers.xsd
rename to framework/src/Volo.Abp.Json.Abstractions/FodyWeavers.xsd
diff --git a/framework/src/Volo.Abp.Json.Core/Volo.Abp.Json.Core.csproj b/framework/src/Volo.Abp.Json.Abstractions/Volo.Abp.Json.Abstractions.csproj
similarity index 92%
rename from framework/src/Volo.Abp.Json.Core/Volo.Abp.Json.Core.csproj
rename to framework/src/Volo.Abp.Json.Abstractions/Volo.Abp.Json.Abstractions.csproj
index b7a88c22f6..15130c129c 100644
--- a/framework/src/Volo.Abp.Json.Core/Volo.Abp.Json.Core.csproj
+++ b/framework/src/Volo.Abp.Json.Abstractions/Volo.Abp.Json.Abstractions.csproj
@@ -5,7 +5,7 @@
netstandard2.0
- Volo.Abp.Json.Core
+ Volo.Abp.Json.Abstractions
$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;
false
false
diff --git a/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/AbpJsonCoreModule.cs b/framework/src/Volo.Abp.Json.Abstractions/Volo/Abp/Json/AbpJsonAbstractionsModule.cs
similarity index 54%
rename from framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/AbpJsonCoreModule.cs
rename to framework/src/Volo.Abp.Json.Abstractions/Volo/Abp/Json/AbpJsonAbstractionsModule.cs
index 68de7be35e..422d34745d 100644
--- a/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/AbpJsonCoreModule.cs
+++ b/framework/src/Volo.Abp.Json.Abstractions/Volo/Abp/Json/AbpJsonAbstractionsModule.cs
@@ -2,7 +2,7 @@
namespace Volo.Abp.Json;
-public class AbpJsonCoreModule : AbpModule
+public class AbpJsonAbstractionsModule : AbpModule
{
}
diff --git a/framework/src/Volo.Abp.Json.Abstractions/Volo/Abp/Json/AbpJsonOptions.cs b/framework/src/Volo.Abp.Json.Abstractions/Volo/Abp/Json/AbpJsonOptions.cs
new file mode 100644
index 0000000000..f7f5370255
--- /dev/null
+++ b/framework/src/Volo.Abp.Json.Abstractions/Volo/Abp/Json/AbpJsonOptions.cs
@@ -0,0 +1,9 @@
+namespace Volo.Abp.Json;
+
+public class AbpJsonOptions
+{
+ ///
+ /// Used to set default value for the DateTimeFormat.
+ ///
+ public string DefaultDateTimeFormat { get; set; }
+}
diff --git a/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/IJsonSerializer.cs b/framework/src/Volo.Abp.Json.Abstractions/Volo/Abp/Json/IJsonSerializer.cs
similarity index 100%
rename from framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/IJsonSerializer.cs
rename to framework/src/Volo.Abp.Json.Abstractions/Volo/Abp/Json/IJsonSerializer.cs
diff --git a/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/AbpHybridJsonSerializer.cs b/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/AbpHybridJsonSerializer.cs
deleted file mode 100644
index f61f8b78ce..0000000000
--- a/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/AbpHybridJsonSerializer.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-using System;
-using System.Linq;
-using JetBrains.Annotations;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Options;
-using Volo.Abp.DependencyInjection;
-
-namespace Volo.Abp.Json;
-
-public class AbpHybridJsonSerializer : IJsonSerializer, ITransientDependency
-{
- protected AbpJsonOptions Options { get; }
-
- protected IServiceScopeFactory ServiceScopeFactory { get; }
-
- public AbpHybridJsonSerializer(IOptions options, IServiceScopeFactory serviceScopeFactory)
- {
- Options = options.Value;
- ServiceScopeFactory = serviceScopeFactory;
- }
-
- public string Serialize([CanBeNull] object obj, bool camelCase = true, bool indented = false)
- {
- using (var scope = ServiceScopeFactory.CreateScope())
- {
- var serializerProvider = GetSerializerProvider(scope.ServiceProvider, obj?.GetType());
- return serializerProvider.Serialize(obj, camelCase, indented);
- }
- }
-
- public T Deserialize([NotNull] string jsonString, bool camelCase = true)
- {
- Check.NotNull(jsonString, nameof(jsonString));
-
- using (var scope = ServiceScopeFactory.CreateScope())
- {
- var serializerProvider = GetSerializerProvider(scope.ServiceProvider, typeof(T));
- return serializerProvider.Deserialize(jsonString, camelCase);
- }
- }
-
- public object Deserialize(Type type, [NotNull] string jsonString, bool camelCase = true)
- {
- Check.NotNull(jsonString, nameof(jsonString));
-
- using (var scope = ServiceScopeFactory.CreateScope())
- {
- var serializerProvider = GetSerializerProvider(scope.ServiceProvider, type);
- return serializerProvider.Deserialize(type, jsonString, camelCase);
- }
- }
-
- protected virtual IJsonSerializerProvider GetSerializerProvider(IServiceProvider serviceProvider, [CanBeNull] Type type)
- {
- foreach (var providerType in Options.Providers.Reverse())
- {
- var provider = serviceProvider.GetRequiredService(providerType) as IJsonSerializerProvider;
- if (provider.CanHandle(type))
- {
- return provider;
- }
- }
-
- throw new AbpException($"There is no IJsonSerializerProvider that can handle '{type.GetFullNameWithAssemblyName()}'!");
- }
-}
diff --git a/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/AbpJsonOptions.cs b/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/AbpJsonOptions.cs
deleted file mode 100644
index ffbd510b93..0000000000
--- a/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/AbpJsonOptions.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Volo.Abp.Collections;
-
-namespace Volo.Abp.Json;
-
-public class AbpJsonOptions
-{
- ///
- /// Used to set default value for the DateTimeFormat.
- ///
- public string DefaultDateTimeFormat { get; set; }
-
- public ITypeList Providers { get; }
-
- public AbpJsonOptions()
- {
- Providers = new TypeList();
- }
-}
diff --git a/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/IJsonSerializerProvider.cs b/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/IJsonSerializerProvider.cs
deleted file mode 100644
index c3ae179d45..0000000000
--- a/framework/src/Volo.Abp.Json.Core/Volo/Abp/Json/IJsonSerializerProvider.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using JetBrains.Annotations;
-
-namespace Volo.Abp.Json;
-
-public interface IJsonSerializerProvider
-{
- bool CanHandle([CanBeNull] Type type);
-
- string Serialize(object obj, bool camelCase = true, bool indented = false);
-
- T Deserialize(string jsonString, bool camelCase = true);
-
- object Deserialize(Type type, string jsonString, bool camelCase = true);
-}
diff --git a/framework/src/Volo.Abp.Json.Newtonsoft/Volo.Abp.Json.Newtonsoft.csproj b/framework/src/Volo.Abp.Json.Newtonsoft/Volo.Abp.Json.Newtonsoft.csproj
index d53a9e2b33..6927cff0db 100644
--- a/framework/src/Volo.Abp.Json.Newtonsoft/Volo.Abp.Json.Newtonsoft.csproj
+++ b/framework/src/Volo.Abp.Json.Newtonsoft/Volo.Abp.Json.Newtonsoft.csproj
@@ -15,7 +15,7 @@
-
+
diff --git a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpCamelCasePropertyNamesContractResolver.cs b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpCamelCasePropertyNamesContractResolver.cs
index 502265db84..a73213af6c 100644
--- a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpCamelCasePropertyNamesContractResolver.cs
+++ b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpCamelCasePropertyNamesContractResolver.cs
@@ -4,8 +4,6 @@ using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Volo.Abp.DependencyInjection;
-using Volo.Abp.Reflection;
-using Volo.Abp.Timing;
namespace Volo.Abp.Json.Newtonsoft;
@@ -20,38 +18,21 @@ public class AbpCamelCasePropertyNamesContractResolver : CamelCasePropertyNamesC
true
);
- NamingStrategy = new CamelCaseNamingStrategy();
+ NamingStrategy = new CamelCaseNamingStrategy
+ {
+ ProcessDictionaryKeys = false
+ };
}
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
var property = base.CreateProperty(member, memberSerialization);
- ModifyProperty(member, property);
-
- return property;
- }
-
- protected virtual void ModifyProperty(MemberInfo member, JsonProperty property)
- {
- if (property.PropertyType != typeof(DateTime) &&
- property.PropertyType != typeof(DateTime?))
- {
- return;
- }
-
- if (ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault(member) == null)
+ if (AbpJsonIsoDateTimeConverter.ShouldNormalize(member, property))
{
property.Converter = _dateTimeConverter.Value;
}
- }
- protected override JsonDictionaryContract CreateDictionaryContract(Type objectType)
- {
- var contract = base.CreateDictionaryContract(objectType);
-
- contract.DictionaryKeyResolver = propertyName => propertyName;
-
- return contract;
+ return property;
}
}
diff --git a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDefaultContractResolver.cs b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDefaultContractResolver.cs
new file mode 100644
index 0000000000..f39f6af578
--- /dev/null
+++ b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDefaultContractResolver.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Reflection;
+using Microsoft.Extensions.DependencyInjection;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
+using Volo.Abp.DependencyInjection;
+
+namespace Volo.Abp.Json.Newtonsoft;
+
+public class AbpDefaultContractResolver : DefaultContractResolver, ITransientDependency
+{
+ private readonly Lazy _dateTimeConverter;
+
+ public AbpDefaultContractResolver(IServiceProvider serviceProvider)
+ {
+ _dateTimeConverter = new Lazy(
+ serviceProvider.GetRequiredService,
+ true
+ );
+ }
+
+ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
+ {
+ var property = base.CreateProperty(member, memberSerialization);
+
+ if (AbpJsonIsoDateTimeConverter.ShouldNormalize(member, property))
+ {
+ property.Converter = _dateTimeConverter.Value;
+ }
+
+ return property;
+ }
+}
diff --git a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpJsonIsoDateTimeConverter.cs b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpJsonIsoDateTimeConverter.cs
index 605f06e9a6..b859688a0d 100644
--- a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpJsonIsoDateTimeConverter.cs
+++ b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpJsonIsoDateTimeConverter.cs
@@ -1,8 +1,11 @@
using System;
+using System.Reflection;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
+using Newtonsoft.Json.Serialization;
using Volo.Abp.DependencyInjection;
+using Volo.Abp.Reflection;
using Volo.Abp.Timing;
namespace Volo.Abp.Json.Newtonsoft;
@@ -43,4 +46,15 @@ public class AbpJsonIsoDateTimeConverter : IsoDateTimeConverter, ITransientDepen
var date = value as DateTime?;
base.WriteJson(writer, date.HasValue ? _clock.Normalize(date.Value) : value, serializer);
}
+
+ internal static bool ShouldNormalize(MemberInfo member, JsonProperty property)
+ {
+ if (property.PropertyType != typeof(DateTime) &&
+ property.PropertyType != typeof(DateTime?))
+ {
+ return false;
+ }
+
+ return ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault(member) == null;
+ }
}
diff --git a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpJsonNewtonsoftModule.cs b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpJsonNewtonsoftModule.cs
index 0989dfdd03..c1f1f3a0cf 100644
--- a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpJsonNewtonsoftModule.cs
+++ b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpJsonNewtonsoftModule.cs
@@ -4,16 +4,11 @@ using Volo.Abp.Timing;
namespace Volo.Abp.Json.Newtonsoft;
-[DependsOn(typeof(AbpJsonCoreModule), typeof(AbpTimingModule))]
+[DependsOn(typeof(AbpJsonAbstractionsModule), typeof(AbpTimingModule))]
public class AbpJsonNewtonsoftModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
- Configure(options =>
- {
- options.Providers.Add();
- });
-
context.Services.AddOptions()
.Configure((options, contractResolver) =>
{
diff --git a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpNewtonsoftJsonSerializerProvider.cs b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpNewtonsoftJsonSerializer.cs
similarity index 80%
rename from framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpNewtonsoftJsonSerializerProvider.cs
rename to framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpNewtonsoftJsonSerializer.cs
index a23580bf6c..36ba95e74c 100644
--- a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpNewtonsoftJsonSerializerProvider.cs
+++ b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpNewtonsoftJsonSerializer.cs
@@ -1,25 +1,24 @@
using System;
using System.Collections.Concurrent;
-using System.Collections.Generic;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Volo.Abp.DependencyInjection;
+
namespace Volo.Abp.Json.Newtonsoft;
-public class AbpNewtonsoftJsonSerializerProvider : IJsonSerializerProvider, ITransientDependency
+[Dependency(ReplaceServices = true)]
+public class AbpNewtonsoftJsonSerializer : IJsonSerializer, ITransientDependency
{
+ protected IServiceProvider ServiceProvider { get; }
protected IOptions Options { get; }
- public AbpNewtonsoftJsonSerializerProvider(IOptions options)
+ public AbpNewtonsoftJsonSerializer(IServiceProvider serviceProvider, IOptions options)
{
+ ServiceProvider = serviceProvider;
Options = options;
}
- public bool CanHandle(Type type)
- {
- return true;
- }
-
public string Serialize(object obj, bool camelCase = true, bool indented = false)
{
return JsonConvert.SerializeObject(obj, CreateJsonSerializerOptions(camelCase, indented));
@@ -35,8 +34,8 @@ public class AbpNewtonsoftJsonSerializerProvider : IJsonSerializerProvider, ITra
return JsonConvert.DeserializeObject(jsonString, type, CreateJsonSerializerOptions(camelCase));
}
- private readonly static ConcurrentDictionary