Skip to content

Commit

Permalink
Fix ulong converter
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmayer-dev committed Apr 14, 2024
1 parent 458f7b1 commit c9571c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ExtensionManifest
[JsonPropertyName("category")]
public string? Category { get; set; }

[JsonPropertyName("author-discord-userid"), JsonConverter(typeof(StringToLongConverter))]
[JsonPropertyName("author-discord-userid"), JsonConverter(typeof(StringToUlongConverter))]
public ulong? AuthorDiscordUserId { get; set; }

[JsonPropertyName("repository")]
Expand Down
22 changes: 0 additions & 22 deletions src/ExtensionStoreAPI.Core/Json/StringToLongConverter.cs

This file was deleted.

22 changes: 22 additions & 0 deletions src/ExtensionStoreAPI.Core/Json/StringToUlongConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace ExtensionStoreAPI.Core.Json;

public class StringToUlongConverter : JsonConverter<ulong>
{
public override ulong Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.String)
{
return 0;
}

return ulong.TryParse(reader.GetString(), out var value) ? value : 0;
}

public override void Write(Utf8JsonWriter writer, ulong value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}

0 comments on commit c9571c2

Please sign in to comment.