mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-09-18 17:48:12 +08:00
fix(work): 修复部分场景下无法反序列化空字符串字段为数值类型的问题
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace System.Text.Json.Converters
|
||||
{
|
||||
internal class TextualNullableLongConverter : JsonConverter<long?>
|
||||
{
|
||||
public override long? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.Null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (reader.TokenType == JsonTokenType.Number)
|
||||
{
|
||||
return reader.GetInt64();
|
||||
}
|
||||
else if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
string? value = reader.GetString();
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return null;
|
||||
|
||||
if (long.TryParse(value, out long l))
|
||||
return l;
|
||||
}
|
||||
|
||||
throw new JsonException();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, long? value, JsonSerializerOptions options)
|
||||
{
|
||||
if (value.HasValue)
|
||||
writer.WriteNumberValue(value.Value);
|
||||
else
|
||||
writer.WriteNullValue();
|
||||
}
|
||||
}
|
||||
}
|
@@ -77,6 +77,7 @@
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("sptime")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("sptime")]
|
||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualNullableLongConverter))]
|
||||
public long? ApproveTimestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -258,8 +259,8 @@
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("s_timestamp")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("s_timestamp")]
|
||||
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
|
||||
public long Timestamp { get; set; }
|
||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualNullableLongConverter))]
|
||||
public long? Timestamp { get; set; }
|
||||
}
|
||||
|
||||
public class SelectorControlValue
|
||||
@@ -498,7 +499,8 @@
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("time")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("time")]
|
||||
public long Timestamp { get; set; }
|
||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualNullableLongConverter))]
|
||||
public long? Timestamp { get; set; }
|
||||
}
|
||||
|
||||
public class RelatedApprovalControlValue
|
||||
@@ -594,7 +596,8 @@
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("time")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("time")]
|
||||
public long Timestamp { get; set; }
|
||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualNullableLongConverter))]
|
||||
public long? Timestamp { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@
|
||||
},
|
||||
"speech": "",
|
||||
"sp_status": 1,
|
||||
"sptime": 0,
|
||||
"sptime": 1234567890,
|
||||
"media_id": []
|
||||
},
|
||||
{
|
||||
@@ -31,7 +31,7 @@
|
||||
},
|
||||
"speech": "",
|
||||
"sp_status": 1,
|
||||
"sptime": 0,
|
||||
"sptime": "",
|
||||
"media_id": []
|
||||
}
|
||||
]
|
||||
|
Reference in New Issue
Block a user