diff --git a/src/Kook.Net.Rest/Net/Converters/NullableUInt32Converter.cs b/src/Kook.Net.Rest/Net/Converters/NullableUInt32Converter.cs index 02ad07c1..ef7df4c0 100644 --- a/src/Kook.Net.Rest/Net/Converters/NullableUInt32Converter.cs +++ b/src/Kook.Net.Rest/Net/Converters/NullableUInt32Converter.cs @@ -7,10 +7,18 @@ internal class NullableUInt32Converter : JsonConverter { public override uint? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - string value = reader.GetString(); - return !string.IsNullOrWhiteSpace(value) && uint.TryParse(value, out uint result) - ? result - : null; + switch (reader.TokenType) + { + case JsonTokenType.String: + string value = reader.GetString(); + return !string.IsNullOrWhiteSpace(value) && uint.TryParse(value, out uint result) + ? result + : null; + case JsonTokenType.Number: + return reader.GetUInt32(); + default: + throw new JsonException($"{nameof(NullableUInt32Converter)} expects string or number token, but got {reader.TokenType}"); + } } public override void Write(Utf8JsonWriter writer, uint? value, JsonSerializerOptions options)