Skip to content

Add MySqlDataReader.GetUtf8JsonReader method #1454

Open
@bgrainger

Description

@bgrainger

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:

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.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions