1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-18 11:52:54 +00:00

Some small fixes in the System.Text.Json ArrayConverter, added support for flags in EnumConverter

This commit is contained in:
Jkorf
2025-01-27 11:52:07 +01:00
parent c693eb8c02
commit 0527a8a76e
3 changed files with 17 additions and 6 deletions
@@ -89,6 +89,10 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
{
if (prop.PropertyInfo.PropertyType == typeof(string))
writer.WriteStringValue(Convert.ToString(objValue, CultureInfo.InvariantCulture));
else if(prop.PropertyInfo.PropertyType.IsEnum)
writer.WriteStringValue(EnumConverter.GetString(objValue));
else if (prop.PropertyInfo.PropertyType == typeof(bool))
writer.WriteBooleanValue((bool)objValue);
else
writer.WriteRawValue(Convert.ToString(objValue, CultureInfo.InvariantCulture)!);
}
@@ -187,12 +191,12 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
_converterOptionsCache.TryAdd(attribute.JsonConverterType, newOptions);
}
value = JsonDocument.ParseValue(ref reader).Deserialize(targetType, newOptions);
value = JsonDocument.ParseValue(ref reader).Deserialize(attribute.PropertyInfo.PropertyType, newOptions);
}
else if (attribute.DefaultDeserialization)
{
// Use default deserialization
value = JsonDocument.ParseValue(ref reader).Deserialize(targetType, options);
value = JsonDocument.ParseValue(ref reader).Deserialize(attribute.PropertyInfo.PropertyType, SerializerOptions.WithConverters);
}
else
{