mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2026-03-10 00:13:36 +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>
|
/// </summary>
|
||||||
[Newtonsoft.Json.JsonProperty("sptime")]
|
[Newtonsoft.Json.JsonProperty("sptime")]
|
||||||
[System.Text.Json.Serialization.JsonPropertyName("sptime")]
|
[System.Text.Json.Serialization.JsonPropertyName("sptime")]
|
||||||
|
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualNullableLongConverter))]
|
||||||
public long? ApproveTimestamp { get; set; }
|
public long? ApproveTimestamp { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -258,8 +259,8 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Newtonsoft.Json.JsonProperty("s_timestamp")]
|
[Newtonsoft.Json.JsonProperty("s_timestamp")]
|
||||||
[System.Text.Json.Serialization.JsonPropertyName("s_timestamp")]
|
[System.Text.Json.Serialization.JsonPropertyName("s_timestamp")]
|
||||||
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
|
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualNullableLongConverter))]
|
||||||
public long Timestamp { get; set; }
|
public long? Timestamp { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SelectorControlValue
|
public class SelectorControlValue
|
||||||
@@ -498,7 +499,8 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Newtonsoft.Json.JsonProperty("time")]
|
[Newtonsoft.Json.JsonProperty("time")]
|
||||||
[System.Text.Json.Serialization.JsonPropertyName("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
|
public class RelatedApprovalControlValue
|
||||||
@@ -594,7 +596,8 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Newtonsoft.Json.JsonProperty("time")]
|
[Newtonsoft.Json.JsonProperty("time")]
|
||||||
[System.Text.Json.Serialization.JsonPropertyName("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": "",
|
"speech": "",
|
||||||
"sp_status": 1,
|
"sp_status": 1,
|
||||||
"sptime": 0,
|
"sptime": 1234567890,
|
||||||
"media_id": []
|
"media_id": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
},
|
},
|
||||||
"speech": "",
|
"speech": "",
|
||||||
"sp_status": 1,
|
"sp_status": 1,
|
||||||
"sptime": 0,
|
"sptime": "",
|
||||||
"media_id": []
|
"media_id": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user