Skip to content

Allow any type to be read as binary #2756

@oliverjanik

Description

@oliverjanik

Hello I'm trying to use the new System.Text.Json with jsonb using Npgsql (v 4.1.2).

Here's the relevant snippet:

using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess);

while (await reader.ReadAsync())
{
    // ...

    var s = await reader.GetStreamAsync(2);
    var result = await JsonSerializer.DeserializeAsync<Dictionary<string, object>>(s);

    // ...
}

I'm getting an exception:

System.InvalidCastException: GetStream() not supported for type jsonb
   at Npgsql.NpgsqlDataReader.GetStream(Int32 ordinal, Boolean async)
   at Npgsql.NpgsqlDataReader.GetStreamAsync(Int32 ordinal, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.GetStreamAsync(Int32 ordinal)

I understand there's reader.GetTextReaderAsync() but that seems useless with the new JsonSerializer.

Would it be difficult to support GetStreamAsync() for jsonb ?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions