diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/Converters/Internal/System.Text.Json/Long/TextualNullableLongConverter.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/Converters/Internal/System.Text.Json/Long/TextualNullableLongConverter.cs new file mode 100644 index 00000000..2cb4e65b --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/Converters/Internal/System.Text.Json/Long/TextualNullableLongConverter.cs @@ -0,0 +1,38 @@ +using System.Text.Json.Serialization; + +namespace System.Text.Json.Converters +{ + internal class TextualNullableLongConverter : JsonConverter + { + 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(); + } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinOA/Approval/CgibinOAGetApprovalDetailResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinOA/Approval/CgibinOAGetApprovalDetailResponse.cs index 14976514..4060111e 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinOA/Approval/CgibinOAGetApprovalDetailResponse.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/Models/CgibinOA/Approval/CgibinOAGetApprovalDetailResponse.cs @@ -77,6 +77,7 @@ /// [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; } /// @@ -258,8 +259,8 @@ /// [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 @@ /// [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 @@ /// [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; } } } diff --git a/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinOA/Approval/CgibinOAGetApprovalDetailResponse.json b/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinOA/Approval/CgibinOAGetApprovalDetailResponse.json index b4c62c1a..c0669167 100644 --- a/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinOA/Approval/CgibinOAGetApprovalDetailResponse.json +++ b/test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/ModelSamples/CgibinOA/Approval/CgibinOAGetApprovalDetailResponse.json @@ -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": [] } ]