using System.Numerics; using System.Text.Json; using System.Text.Json.Serialization; namespace Supercell.Laser.Server.Database { public class BigIntegerJsonConverter : JsonConverter { public override BigInteger Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType == JsonTokenType.String) { string s = reader.GetString(); if (BigInteger.TryParse(s, out BigInteger result)) return result; return BigInteger.Zero; } if (reader.TokenType == JsonTokenType.Number) { if (reader.TryGetInt64(out long l)) return new BigInteger(l); return BigInteger.Zero; } return BigInteger.Zero; } public override void Write(Utf8JsonWriter writer, BigInteger value, JsonSerializerOptions options) { writer.WriteStringValue(value.ToString()); } } }