diff options
author | Rory& <root@rory.gay> | 2024-06-17 06:17:03 +0200 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2024-06-17 06:25:20 +0200 |
commit | 99294322327f899eb01e9c78c0681528cada99d1 (patch) | |
tree | 023a30b463867deb4c8b1b9df8c8b11770846860 /LibMatrix/Extensions/JsonConverters.cs | |
parent | Single httpclient implementation (diff) | |
download | LibMatrix-99294322327f899eb01e9c78c0681528cada99d1.tar.xz |
Single HTTP client fixes github/dev/new-httpclient dev/new-httpclient
Diffstat (limited to 'LibMatrix/Extensions/JsonConverters.cs')
-rw-r--r-- | LibMatrix/Extensions/JsonConverters.cs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/LibMatrix/Extensions/JsonConverters.cs b/LibMatrix/Extensions/JsonConverters.cs new file mode 100644 index 0000000..eed3fb2 --- /dev/null +++ b/LibMatrix/Extensions/JsonConverters.cs @@ -0,0 +1,29 @@ +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace LibMatrix.Extensions; + +public class JsonFloatStringConverter : JsonConverter<float> { + public override float Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => float.Parse(reader.GetString()!); + + public override void Write(Utf8JsonWriter writer, float value, JsonSerializerOptions options) + => writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); +} + +public class JsonDoubleStringConverter : JsonConverter<double> { + public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => double.Parse(reader.GetString()!); + + public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options) + => writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); +} + +public class JsonDecimalStringConverter : JsonConverter<decimal> { + public override decimal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => decimal.Parse(reader.GetString()!); + + public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerOptions options) + => writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); +} \ No newline at end of file |