diff --git a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs
index 5e698956b3..408f38e772 100644
--- a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs
+++ b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs
@@ -14,7 +14,7 @@ namespace Volo.Abp.Json.Newtonsoft;
public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency
{
- private readonly string _dateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
+ private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
private readonly DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
private readonly CultureInfo _culture = CultureInfo.InvariantCulture;
private readonly IClock _clock;
@@ -72,10 +72,7 @@ public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency
}
}
- var date = !_dateTimeFormat.IsNullOrEmpty() ?
- DateTime.ParseExact(dateText, _dateTimeFormat, _culture, _dateTimeStyles) :
- DateTime.Parse(dateText, _culture, _dateTimeStyles);
-
+ var date = DateTime.Parse(dateText, _culture, _dateTimeStyles);
return _clock.Normalize(date);
}
@@ -95,7 +92,7 @@ public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency
}
writer.WriteValue(_options.OutputDateTimeFormat.IsNullOrWhiteSpace()
- ? dateTime.ToString(_dateTimeFormat, _culture)
+ ? dateTime.ToString(DefaultDateTimeFormat, _culture)
: dateTime.ToString(_options.OutputDateTimeFormat, _culture));
}
else
@@ -104,7 +101,7 @@ public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency
}
}
- internal static bool ShouldNormalize(MemberInfo member, JsonProperty property)
+ static internal bool ShouldNormalize(MemberInfo member, JsonProperty property)
{
if (property.PropertyType != typeof(DateTime) &&
property.PropertyType != typeof(DateTime?))
diff --git a/framework/test/Volo.Abp.Json.Tests/Volo.Abp.Json.Tests.csproj b/framework/test/Volo.Abp.Json.Tests/Volo.Abp.Json.Tests.csproj
index 9d1bad51f2..f5ceee7c40 100644
--- a/framework/test/Volo.Abp.Json.Tests/Volo.Abp.Json.Tests.csproj
+++ b/framework/test/Volo.Abp.Json.Tests/Volo.Abp.Json.Tests.csproj
@@ -9,7 +9,8 @@
-
+
+
diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIgnorePropertiesModifiers_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIgnorePropertiesModifiers_Tests.cs
index 138ffd46a7..7be045874a 100644
--- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIgnorePropertiesModifiers_Tests.cs
+++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIgnorePropertiesModifiers_Tests.cs
@@ -7,7 +7,7 @@ using Xunit;
namespace Volo.Abp.Json;
-public class AbpIgnorePropertiesModifiers_Tests : AbpJsonTestBase
+public class AbpIgnorePropertiesModifiers_Tests : AbpJsonSystemTextJsonTestBase
{
private readonly IJsonSerializer _jsonSerializer;
diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIncludeNonPublicPropertiesModifiers_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIncludeNonPublicPropertiesModifiers_Tests.cs
index 38d733a3d8..c6d961d2b7 100644
--- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIncludeNonPublicPropertiesModifiers_Tests.cs
+++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIncludeNonPublicPropertiesModifiers_Tests.cs
@@ -6,7 +6,7 @@ using Xunit;
namespace Volo.Abp.Json;
-public class AbpIncludeNonPublicPropertiesModifiers_Tests : AbpJsonTestBase
+public class AbpIncludeNonPublicPropertiesModifiers_Tests : AbpJsonSystemTextJsonTestBase
{
private readonly IJsonSerializer _jsonSerializer;
diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonNewtonsoftTestModule.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonNewtonsoftTestModule.cs
new file mode 100644
index 0000000000..42559397da
--- /dev/null
+++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonNewtonsoftTestModule.cs
@@ -0,0 +1,26 @@
+using Volo.Abp.Autofac;
+using Volo.Abp.Json.Newtonsoft;
+using Volo.Abp.Json.SystemTextJson;
+using Volo.Abp.Modularity;
+
+namespace Volo.Abp.Json;
+
+[DependsOn(
+ typeof(AbpAutofacModule),
+ typeof(AbpJsonSystemTextJsonModule),
+ typeof(AbpTestBaseModule)
+)]
+public class AbpJsonSystemTextJsonTestModule : AbpModule
+{
+
+}
+
+[DependsOn(
+ typeof(AbpAutofacModule),
+ typeof(AbpJsonNewtonsoftModule),
+ typeof(AbpTestBaseModule)
+)]
+public class AbpJsonNewtonsoftTestModule : AbpModule
+{
+
+}
diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonSystemTextJsonTestBase.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonSystemTextJsonTestBase.cs
new file mode 100644
index 0000000000..ebae706aca
--- /dev/null
+++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonSystemTextJsonTestBase.cs
@@ -0,0 +1,19 @@
+using Volo.Abp.Testing;
+
+namespace Volo.Abp.Json;
+
+public abstract class AbpJsonSystemTextJsonTestBase : AbpIntegratedTest
+{
+ protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
+ {
+ options.UseAutofac();
+ }
+}
+
+public abstract class AbpJsonNewtonsoftJsonTestBase : AbpIntegratedTest
+{
+ protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
+ {
+ options.UseAutofac();
+ }
+}
diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestBase.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestBase.cs
deleted file mode 100644
index ef31c7516f..0000000000
--- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestBase.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Volo.Abp.Testing;
-
-namespace Volo.Abp.Json;
-
-public abstract class AbpJsonTestBase : AbpIntegratedTest
-{
- protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
- {
- options.UseAutofac();
- }
-}
diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestModule.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestModule.cs
deleted file mode 100644
index 0fd3cbd1cf..0000000000
--- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestModule.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using Volo.Abp.Autofac;
-using Volo.Abp.Modularity;
-
-namespace Volo.Abp.Json;
-
-[DependsOn(
- typeof(AbpAutofacModule),
- typeof(AbpJsonModule),
- typeof(AbpTestBaseModule)
-)]
-public class AbpJsonTestModule : AbpModule
-{
-
-}
diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs
index f605914d6e..e32df85d7f 100644
--- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs
+++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs
@@ -9,11 +9,11 @@ using Xunit;
namespace Volo.Abp.Json;
-public abstract class AbpSystemTextJsonSerializerProvider_TestBase : AbpJsonTestBase
+public abstract class AbpSystemTextJsonSerializerProviderTestBase : AbpJsonSystemTextJsonTestBase
{
protected AbpSystemTextJsonSerializer JsonSerializer;
- public AbpSystemTextJsonSerializerProvider_TestBase()
+ public AbpSystemTextJsonSerializerProviderTestBase()
{
JsonSerializer = GetRequiredService();
}
@@ -72,7 +72,7 @@ public abstract class AbpSystemTextJsonSerializerProvider_TestBase : AbpJsonTest
}
}
-public class AbpSystemTextJsonSerializerProvider_Tests : AbpSystemTextJsonSerializerProvider_TestBase
+public class AbpSystemTextJsonSerializerProviderTests : AbpSystemTextJsonSerializerProviderTestBase
{
[Fact]
public void Serialize_Deserialize_With_Boolean()
@@ -214,7 +214,7 @@ public class AbpSystemTextJsonSerializerProvider_Tests : AbpSystemTextJsonSerial
}
}
-public class AbpSystemTextJsonSerializerProvider_DateTimeFormat_Tests : AbpSystemTextJsonSerializerProvider_TestBase
+public class AbpSystemTextJsonSerializerProviderDateTimeFormatTests : AbpSystemTextJsonSerializerProviderTestBase
{
protected override void AfterAddApplication(IServiceCollection services)
{
@@ -270,7 +270,7 @@ public class AbpSystemTextJsonSerializerProvider_DateTimeFormat_Tests : AbpSyste
}
}
-public abstract class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests : AbpSystemTextJsonSerializerProvider_TestBase
+public abstract class AbpSystemTextJsonSerializerProviderDatetimeKindTests : AbpSystemTextJsonSerializerProviderTestBase
{
protected DateTimeKind Kind { get; set; } = DateTimeKind.Unspecified;
@@ -283,7 +283,7 @@ public abstract class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests :
}
}
-public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_UTC_Tests : AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests
+public class AbpSystemTextJsonSerializerProviderDatetimeKindUtcTests : AbpSystemTextJsonSerializerProviderDatetimeKindTests
{
protected override void AfterAddApplication(IServiceCollection services)
{
@@ -292,7 +292,7 @@ public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_UTC_Tests : AbpSy
}
}
-public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Local_Tests : AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests
+public class AbpSystemTextJsonSerializerProviderDatetimeKindLocalTests : AbpSystemTextJsonSerializerProviderDatetimeKindTests
{
protected override void AfterAddApplication(IServiceCollection services)
{
@@ -301,7 +301,7 @@ public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Local_Tests : Abp
}
}
-public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Unspecified_Tests : AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests
+public class AbpSystemTextJsonSerializerProviderDatetimeKindUnspecifiedTests : AbpSystemTextJsonSerializerProviderDatetimeKindTests
{
}
diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObjectModifiers_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObjectModifiers_Tests.cs
index 0bb538f9d1..d0337b2d9d 100644
--- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObjectModifiers_Tests.cs
+++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObjectModifiers_Tests.cs
@@ -6,7 +6,7 @@ using Xunit;
namespace Volo.Abp.Json;
-public class ExtensibleObjectModifiers_Tests : AbpJsonTestBase
+public class ExtensibleObjectModifiers_Tests : AbpJsonSystemTextJsonTestBase
{
[Fact]
public void Should_Modify_Object()
diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObject_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObject_Tests.cs
index a5bcb723db..91aafccb81 100644
--- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObject_Tests.cs
+++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObject_Tests.cs
@@ -7,7 +7,7 @@ using Xunit;
namespace Volo.Abp.Json;
-public class ExtensibleObject_Tests : AbpJsonTestBase
+public class ExtensibleObject_Tests : AbpJsonSystemTextJsonTestBase
{
private readonly IJsonSerializer _jsonSerializer;
diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/InputAndOutputDateTimeFormat_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/InputAndOutputDateTimeFormat_Tests.cs
new file mode 100644
index 0000000000..cf6356477d
--- /dev/null
+++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/InputAndOutputDateTimeFormat_Tests.cs
@@ -0,0 +1,112 @@
+using System;
+using System.Collections.Generic;
+using Microsoft.Extensions.DependencyInjection;
+using Shouldly;
+using Volo.Abp.Timing;
+using Xunit;
+
+namespace Volo.Abp.Json;
+
+public class InputAndOutputDateTimeFormatSystemTextJsonTests : AbpJsonSystemTextJsonTestBase
+{
+ private readonly IJsonSerializer _jsonSerializer;
+
+ public InputAndOutputDateTimeFormatSystemTextJsonTests()
+ {
+ _jsonSerializer = GetRequiredService();
+ }
+
+ protected override void AfterAddApplication(IServiceCollection services)
+ {
+ services.Configure(options =>
+ {
+ options.InputDateTimeFormats = new List()
+ {
+ "yyyy*MM*dd",
+ "yyyy-MM-dd HH:mm:ss"
+ };
+ options.OutputDateTimeFormat = "yyyy*MM-dd HH:mm:ss";
+ });
+ services.Configure(options =>
+ {
+ options.Kind = DateTimeKind.Utc;
+ });
+ }
+
+ [Fact]
+ public void InputAndOutputDateTimeFormat_Test()
+ {
+ var resultDate = new DateTime(2016, 04, 13, 08, 58, 10, DateTimeKind.Utc);
+ var json = _jsonSerializer.Serialize(new DateTimeDto()
+ {
+ DateTime1 = resultDate,
+ DateTime2 = resultDate
+ });
+ json.ShouldContain("\"DateTime1\":\"2016*04-13 08:58:10\"");
+ json.ShouldContain("\"DateTime2\":\"2016*04-13 08:58:10\"");
+
+ var dto = _jsonSerializer.Deserialize("{\"DateTime1\":\"" + resultDate.ToString("yyyy*MM*dd") + "\",\"DateTime2\":\"" + resultDate.ToString("yyyy-MM-dd HH:mm:ss") + "\"}");
+ dto.DateTime1.ShouldBe(resultDate.Date);
+ dto.DateTime1.Kind.ShouldBe(DateTimeKind.Utc);
+ dto.DateTime2.ShouldBe(resultDate);
+ dto.DateTime2.Value.Kind.ShouldBe(DateTimeKind.Utc);
+ }
+
+ public class DateTimeDto
+ {
+ public DateTime DateTime1 { get; set; }
+ public DateTime? DateTime2 { get; set; }
+ }
+}
+
+public class InputAndOutputDateTimeFormatNewtonsoftTests : AbpJsonNewtonsoftJsonTestBase
+{
+ private readonly IJsonSerializer _jsonSerializer;
+
+ public InputAndOutputDateTimeFormatNewtonsoftTests()
+ {
+ _jsonSerializer = GetRequiredService();
+ }
+
+ protected override void AfterAddApplication(IServiceCollection services)
+ {
+ services.Configure(options =>
+ {
+ options.InputDateTimeFormats = new List()
+ {
+ "yyyy*MM*dd",
+ "yyyy-MM-dd HH:mm:ss"
+ };
+ options.OutputDateTimeFormat = "yyyy*MM-dd HH:mm:ss";
+ });
+ services.Configure(options =>
+ {
+ options.Kind = DateTimeKind.Utc;
+ });
+ }
+
+ [Fact]
+ public void InputAndOutputDateTimeFormat_Test()
+ {
+ var resultDate = new DateTime(2016, 04, 13, 08, 58, 10, DateTimeKind.Utc);
+ var json = _jsonSerializer.Serialize(new DateTimeDto()
+ {
+ DateTime1 = resultDate,
+ DateTime2 = resultDate
+ });
+ json.ShouldContain("\"DateTime1\":\"2016*04-13 08:58:10\"");
+ json.ShouldContain("\"DateTime2\":\"2016*04-13 08:58:10\"");
+
+ var dto = _jsonSerializer.Deserialize("{\"DateTime1\":\"" + resultDate.ToString("yyyy*MM*dd") + "\",\"DateTime2\":\"" + resultDate.ToString("yyyy-MM-dd HH:mm:ss") + "\"}");
+ dto.DateTime1.ShouldBe(resultDate.Date);
+ dto.DateTime1.Kind.ShouldBe(DateTimeKind.Utc);
+ dto.DateTime2.ShouldBe(resultDate);
+ dto.DateTime2.Value.Kind.ShouldBe(DateTimeKind.Utc);
+ }
+
+ public class DateTimeDto
+ {
+ public DateTime DateTime1 { get; set; }
+ public DateTime? DateTime2 { get; set; }
+ }
+}