btcpayserver/BTCPayServer.Client/JsonConverters/MoneyJsonConverter.cs
2020-06-28 17:55:27 +09:00

26 lines
849 B
C#

using System;
using System.Globalization;
using NBitcoin;
using Newtonsoft.Json;
namespace BTCPayServer.Client.JsonConverters
{
public class MoneyJsonConverter : NBitcoin.JsonConverters.MoneyJsonConverter
{
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.String)
{
return new Money(long.Parse((string)reader.Value));
}
return base.ReadJson(reader, objectType, existingValue, serializer);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value != null)
writer.WriteValue(((Money)value).Satoshi.ToString(CultureInfo.InvariantCulture));
}
}
}