Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ArrrayConverter serialization of nullable types #226

Closed
wants to merge 1 commit into from

Conversation

nils2525
Copy link

@nils2525 nils2525 commented Feb 4, 2025

Fixed an error I encountered when trying to serialise the Nullable<bool> property BitfinexTradeDetails.Maker.

  System.Text.Json.JsonReaderException: 'T' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
   at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)
   at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
   at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.Utf8JsonWriter.WriteRawValueCore(ReadOnlySpan`1 utf8Json, Boolean skipInputValidation)
   at System.Text.Json.Utf8JsonWriter.TranscodeAndWriteRawValue(ReadOnlySpan`1 json, Boolean skipInputValidation)
   at System.Text.Json.Utf8JsonWriter.WriteRawValue(String json, Boolean skipInputValidation)
   at CryptoExchange.Net.Converters.SystemTextJson.ArrayConverter.ArrayConverterInner`1.Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) in C:\Dev\CryptoExchangeNet\CryptoExchange.Net\CryptoExchange.Net\Converters\SystemTextJson\ArrayConverter.cs:line 97
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsObject(Utf8JsonWriter writer, Object rootValue)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
   at System.Text.Json.JsonSerializer.WriteString[TValue](TValue& value, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)

@JKorf
Copy link
Owner

JKorf commented Feb 5, 2025

Hi, there was already a cached property for the underlying type, so I used that to instead of getting the underlying type each time. Thanks for bringing this to my attention. (and your contributions in the other libraries)

@JKorf JKorf closed this Feb 5, 2025
@nils2525 nils2525 deleted the feature/ArrayConverterFix branch February 5, 2025 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants