Skip to content

Commit

Permalink
Fixed incorrect json converter resulting in startup failure
Browse files Browse the repository at this point in the history
  • Loading branch information
gehongyan committed Dec 25, 2022
1 parent 8eefe5e commit 7955aef
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Kook.Net.Rest/Net/Converters/NullableUInt32Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ internal class NullableUInt32Converter : JsonConverter<uint?>
{
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)
Expand Down

0 comments on commit 7955aef

Please sign in to comment.