Skip to content

Odd behavior with JsonNode as parameter. #6578

@PetSerAl

Description

@PetSerAl

JsonNode have no way to represent JSON null as object. Instead JsonNode represent JSON null as null reference: JsonNode.Parse("null") is null returns true. That cause some issues when passing such value as NpgsqlParameter.

When using non-generic NpgsqlParameter: new NpgsqlParameter { NpgsqlDbType = NpgsqlDbType.Jsonb, Value = JsonNode.Parse("null") } it cause exception: System.InvalidOperationException: Parameter '' cannot be null, DBNull.Value should be used instead. That is understandable as no type information associated with null reference.

With generic NpgsqlParameter: new NpgsqlParameter<JsonNode> { NpgsqlDbType = NpgsqlDbType.Jsonb, TypedValue = JsonNode.Parse("null") } it passes value as SQL NULL, but not as JSON null.

As I can see, there is no way to pass JSON null value by using JsonNode. There is no issue when JSON null is part of JSON array or JSON object. Only when JSON null is entire JSON document.

Not sure if current behavior could/should be changed from compatibility point of view, but it definitely should be documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions