Skip to content

JsonNode[] missing from basic JSON types. #6517

@PetSerAl

Description

@PetSerAl

It seems mapping for JsonNode[] is missing in from JsonTypeInfoResolverFactory:

static TypeInfoMappingCollection AddMappings(TypeInfoMappingCollection mappings)
{
foreach (var dataTypeName in new[] { DataTypeNames.Jsonb, DataTypeNames.Json })
{
mappings.AddArrayType<JsonDocument>(dataTypeName);
mappings.AddStructArrayType<JsonElement>(dataTypeName);
mappings.AddArrayType<JsonObject>(dataTypeName);
mappings.AddArrayType<JsonArray>(dataTypeName);
mappings.AddArrayType<JsonValue>(dataTypeName);
}
return mappings;
}

So invoking command with parameter:

new NpgsqlParameter() { NpgsqlDbType = NpgsqlDbType.Array | NpgsqlDbType.Jsonb, Value = (JsonNode[])[...] }

throws exeption:

Type 'JsonNode[]' required dynamic JSON serialization, which requires an explicit opt-in; call 'EnableDynamicJson' on 'NpgsqlDataSourceBuilder' or NpgsqlConnection.GlobalTypeMapper

While

new NpgsqlParameter() { NpgsqlDbType = NpgsqlDbType.Array | NpgsqlDbType.Jsonb, Value = (JsonObject[])[...] }
new NpgsqlParameter() { NpgsqlDbType = NpgsqlDbType.Array | NpgsqlDbType.Jsonb, Value = (object[])[...] }

works fine.

Npgsql vesion: 10.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions