Description
From #1451 (comment):
Would it make sense to add a similar option to read JSON columns as byte[] (instead of a string)?
On .NET 6.0 and later, MySqlDataReader
could expose a GetUtf8JsonReader
method that returns a Utf8JsonReader. This would allow users to call JsonNode.Parse or JsonSerializer.Deserialize to read straight from MySqlConnector's buffer.
Reasons not to do this could be:
Utf8JsonReader
is aref struct
that can't be used in async methods- Lifetime concerns about reading the JSON before
MySqlDataReader.Read(Async)
is called again; see discussion at Span-based way to read binary data in ADO.NET dotnet/runtime#24899
Exposing ReadOnlyMemory<byte>
would allow JsonDocument.Parse to be called, but that could introduce serious lifetime issues because "the ReadOnlyMemory value will be used for the entire lifetime of the JsonDocument object, and the caller must ensure that the data therein does not change during the object lifetime." (ReadOnlyMemory<byte>
would also allow Utf8JsonReader
to be constructed from its .Span
, enabling the scenarios above.)