diff --git a/CryptoExchange.Net/Converters/SystemTextJson/ArrayConverter.cs b/CryptoExchange.Net/Converters/SystemTextJson/ArrayConverter.cs index ad399b45..ec6f0eda 100644 --- a/CryptoExchange.Net/Converters/SystemTextJson/ArrayConverter.cs +++ b/CryptoExchange.Net/Converters/SystemTextJson/ArrayConverter.cs @@ -32,6 +32,7 @@ private class ArrayPropertyInfo public ArrayPropertyAttribute ArrayProperty { get; set; } = null!; public Type? JsonConverterType { get; set; } public bool DefaultDeserialization { get; set; } + public Type TargetType { get; set; } } private class ArrayConverterInner : JsonConverter @@ -70,7 +71,8 @@ private static List CacheTypeAttributes(Type type) ArrayProperty = att, PropertyInfo = property, DefaultDeserialization = property.GetCustomAttribute() != null, - JsonConverterType = property.GetCustomAttribute()?.ConverterType + JsonConverterType = property.GetCustomAttribute()?.ConverterType, + TargetType = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType }); } @@ -96,8 +98,7 @@ private static object ParseObject(ref Utf8JsonReader reader, object result, Type if (attribute == null) continue; - var targetType = attribute.PropertyInfo.PropertyType; - + var targetType = attribute.TargetType; object? value = null; if (attribute.JsonConverterType != null) { @@ -124,7 +125,7 @@ private static object ParseObject(ref Utf8JsonReader reader, object result, Type }; } - attribute.PropertyInfo.SetValue(result, value == null ? null : Convert.ChangeType(value, attribute.PropertyInfo.PropertyType, CultureInfo.InvariantCulture)); + attribute.PropertyInfo.SetValue(result, value == null ? null : Convert.ChangeType(value, targetType, CultureInfo.InvariantCulture)); index++; }