mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-09-18 17:48:12 +08:00
feat(tenpayv3): 调整非公共 JsonConverter 的作用域
This commit is contained in:
@@ -5,7 +5,7 @@ using Newtonsoft.Json.Converters;
|
|||||||
|
|
||||||
namespace Newtonsoft.Json.Converters
|
namespace Newtonsoft.Json.Converters
|
||||||
{
|
{
|
||||||
public class CommonWithoutSeparatorsDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
|
internal class CommonWithoutSeparatorsDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
|
||||||
{
|
{
|
||||||
private readonly JsonConverter<DateTimeOffset?> _converter = new CommonWithoutSeparatorsNullableDateTimeOffsetConverter();
|
private readonly JsonConverter<DateTimeOffset?> _converter = new CommonWithoutSeparatorsNullableDateTimeOffsetConverter();
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ using Newtonsoft.Json.Converters;
|
|||||||
|
|
||||||
namespace Newtonsoft.Json.Converters
|
namespace Newtonsoft.Json.Converters
|
||||||
{
|
{
|
||||||
public class CommonWithoutSeparatorsNullableDateTimeOffsetConverter : JsonConverter<DateTimeOffset?>
|
internal class CommonWithoutSeparatorsNullableDateTimeOffsetConverter : JsonConverter<DateTimeOffset?>
|
||||||
{
|
{
|
||||||
internal const string DATETIME_FORMAT = "yyyyMMddHHmmss";
|
internal const string DATETIME_FORMAT = "yyyyMMddHHmmss";
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ using System.Text.Json.Serialization;
|
|||||||
|
|
||||||
namespace System.Text.Json.Converters
|
namespace System.Text.Json.Converters
|
||||||
{
|
{
|
||||||
public class CommonWithoutSeparatorsDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
|
internal class CommonWithoutSeparatorsDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
|
||||||
{
|
{
|
||||||
private readonly JsonConverter<DateTimeOffset?> _converter = new CommonWithoutSeparatorsNullableDateTimeOffsetConverter();
|
private readonly JsonConverter<DateTimeOffset?> _converter = new CommonWithoutSeparatorsNullableDateTimeOffsetConverter();
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ using System.Text.Json.Serialization;
|
|||||||
|
|
||||||
namespace System.Text.Json.Converters
|
namespace System.Text.Json.Converters
|
||||||
{
|
{
|
||||||
public class CommonWithoutSeparatorsNullableDateTimeOffsetConverter : JsonConverter<DateTimeOffset?>
|
internal class CommonWithoutSeparatorsNullableDateTimeOffsetConverter : JsonConverter<DateTimeOffset?>
|
||||||
{
|
{
|
||||||
private const string DATETIME_FORMAT = Newtonsoft.Json.Converters.CommonWithoutSeparatorsNullableDateTimeOffsetConverter.DATETIME_FORMAT;
|
private const string DATETIME_FORMAT = Newtonsoft.Json.Converters.CommonWithoutSeparatorsNullableDateTimeOffsetConverter.DATETIME_FORMAT;
|
||||||
|
|
||||||
|
@@ -22,18 +22,6 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
|
|||||||
[System.Text.Json.Serialization.JsonPropertyName("nullable_datetime_rfc3339")]
|
[System.Text.Json.Serialization.JsonPropertyName("nullable_datetime_rfc3339")]
|
||||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.RFC3339NullableDateTimeOffsetConverter))]
|
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.RFC3339NullableDateTimeOffsetConverter))]
|
||||||
public DateTimeOffset? NullableDateTimeWithRFC3339 { get; set; }
|
public DateTimeOffset? NullableDateTimeWithRFC3339 { get; set; }
|
||||||
|
|
||||||
[Newtonsoft.Json.JsonProperty("datetime_common_nosep")]
|
|
||||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.CommonWithoutSeparatorsDateTimeOffsetConverter))]
|
|
||||||
[System.Text.Json.Serialization.JsonPropertyName("datetime_common_nosep")]
|
|
||||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.CommonWithoutSeparatorsDateTimeOffsetConverter))]
|
|
||||||
public DateTimeOffset DateTimeWithFullNoSep { get; set; }
|
|
||||||
|
|
||||||
[Newtonsoft.Json.JsonProperty("nullable_datetime_common_nosep")]
|
|
||||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.CommonWithoutSeparatorsNullableDateTimeOffsetConverter))]
|
|
||||||
[System.Text.Json.Serialization.JsonPropertyName("nullable_datetime_common_nosep")]
|
|
||||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.CommonWithoutSeparatorsNullableDateTimeOffsetConverter))]
|
|
||||||
public DateTimeOffset? NullableDateTimeWithFullNoSep { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class JsonStringTypedStringListOrArrayTestEntity
|
class JsonStringTypedStringListOrArrayTestEntity
|
||||||
@@ -61,7 +49,6 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
|
|||||||
public void JsonDateTimeOffsetTest()
|
public void JsonDateTimeOffsetTest()
|
||||||
{
|
{
|
||||||
const string FORMAT_RFC3339 = "yyyy-MM-dd'T'HH:mm:sszzz";
|
const string FORMAT_RFC3339 = "yyyy-MM-dd'T'HH:mm:sszzz";
|
||||||
const string FORMAT_FullNoSep = "yyyyMMddHHmmss";
|
|
||||||
|
|
||||||
string datestr = "2018-06-08T10:34:56+08:00";
|
string datestr = "2018-06-08T10:34:56+08:00";
|
||||||
var date = DateTimeOffset.Parse(datestr);
|
var date = DateTimeOffset.Parse(datestr);
|
||||||
@@ -70,40 +57,29 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
|
|||||||
Assert.Equal(datestr, date.ToString(FORMAT_RFC3339));
|
Assert.Equal(datestr, date.ToString(FORMAT_RFC3339));
|
||||||
|
|
||||||
raw.DateTimeWithRFC3339 = date;
|
raw.DateTimeWithRFC3339 = date;
|
||||||
raw.DateTimeWithFullNoSep = date;
|
|
||||||
raw.NullableDateTimeWithRFC3339 = date;
|
raw.NullableDateTimeWithRFC3339 = date;
|
||||||
raw.NullableDateTimeWithFullNoSep = date;
|
|
||||||
var json = new FlurlNewtonsoftJsonSerializer().Serialize(raw);
|
var json = new FlurlNewtonsoftJsonSerializer().Serialize(raw);
|
||||||
var entity = new FlurlNewtonsoftJsonSerializer().Deserialize<JsonDateTimeOffsetTestEntity>(json);
|
var entity = new FlurlNewtonsoftJsonSerializer().Deserialize<JsonDateTimeOffsetTestEntity>(json);
|
||||||
|
|
||||||
Assert.Contains($"\"datetime_rfc3339\":\"{datestr}\"", json);
|
Assert.Contains($"\"datetime_rfc3339\":\"{datestr}\"", json);
|
||||||
Assert.Contains($"\"datetime_common_nosep\":\"{date.ToString(FORMAT_FullNoSep)}\"", json);
|
|
||||||
Assert.Contains($"\"nullable_datetime_rfc3339\":\"{datestr}\"", json);
|
Assert.Contains($"\"nullable_datetime_rfc3339\":\"{datestr}\"", json);
|
||||||
Assert.Contains($"\"nullable_datetime_common_nosep\":\"{date.ToString(FORMAT_FullNoSep)}\"", json);
|
|
||||||
Assert.Equal(raw.DateTimeWithRFC3339, entity.DateTimeWithRFC3339);
|
Assert.Equal(raw.DateTimeWithRFC3339, entity.DateTimeWithRFC3339);
|
||||||
Assert.Equal(raw.DateTimeWithFullNoSep, entity.DateTimeWithFullNoSep);
|
|
||||||
Assert.Equal(raw.NullableDateTimeWithRFC3339, entity.NullableDateTimeWithRFC3339);
|
Assert.Equal(raw.NullableDateTimeWithRFC3339, entity.NullableDateTimeWithRFC3339);
|
||||||
Assert.Equal(raw.NullableDateTimeWithFullNoSep, entity.NullableDateTimeWithFullNoSep);
|
|
||||||
|
|
||||||
raw.NullableDateTimeWithRFC3339 = null;
|
raw.NullableDateTimeWithRFC3339 = null;
|
||||||
raw.NullableDateTimeWithFullNoSep = null;
|
|
||||||
json = new FlurlNewtonsoftJsonSerializer().Serialize(raw);
|
json = new FlurlNewtonsoftJsonSerializer().Serialize(raw);
|
||||||
entity = new FlurlNewtonsoftJsonSerializer().Deserialize<JsonDateTimeOffsetTestEntity>(json);
|
entity = new FlurlNewtonsoftJsonSerializer().Deserialize<JsonDateTimeOffsetTestEntity>(json);
|
||||||
|
|
||||||
Assert.Equal(datestr, date.ToString(FORMAT_RFC3339));
|
Assert.Equal(datestr, date.ToString(FORMAT_RFC3339));
|
||||||
Assert.DoesNotContain($"\"nullable_datetime_rfc3339\"", json);
|
Assert.DoesNotContain($"\"nullable_datetime_rfc3339\"", json);
|
||||||
Assert.DoesNotContain($"\"nullable_datetime_common_nosep\"", json);
|
|
||||||
Assert.Null(entity.NullableDateTimeWithRFC3339);
|
Assert.Null(entity.NullableDateTimeWithRFC3339);
|
||||||
Assert.Null(entity.NullableDateTimeWithFullNoSep);
|
|
||||||
|
|
||||||
json = new FlurlSystemTextJsonSerializer().Serialize(raw);
|
json = new FlurlSystemTextJsonSerializer().Serialize(raw);
|
||||||
entity = new FlurlSystemTextJsonSerializer().Deserialize<JsonDateTimeOffsetTestEntity>(json);
|
entity = new FlurlSystemTextJsonSerializer().Deserialize<JsonDateTimeOffsetTestEntity>(json);
|
||||||
|
|
||||||
Assert.Equal(datestr, date.ToString(FORMAT_RFC3339));
|
Assert.Equal(datestr, date.ToString(FORMAT_RFC3339));
|
||||||
Assert.DoesNotContain($"\"nullable_datetime_rfc3339\"", json);
|
Assert.DoesNotContain($"\"nullable_datetime_rfc3339\"", json);
|
||||||
Assert.DoesNotContain($"\"nullable_datetime_common_nosep\"", json);
|
|
||||||
Assert.Null(entity.NullableDateTimeWithRFC3339);
|
Assert.Null(entity.NullableDateTimeWithRFC3339);
|
||||||
Assert.Null(entity.NullableDateTimeWithFullNoSep);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact(DisplayName = "字符串类型的字符串列表、数组 JSON 序列化 / 反序列化")]
|
[Fact(DisplayName = "字符串类型的字符串列表、数组 JSON 序列化 / 反序列化")]
|
||||||
|
Reference in New Issue
Block a user