Skip to content

Fix arrays over JsonDocument/JsonElement#3747

Merged
roji merged 1 commit intonpgsql:mainfrom
roji:JsonDocumentArray
Feb 22, 2026
Merged

Fix arrays over JsonDocument/JsonElement#3747
roji merged 1 commit intonpgsql:mainfrom
roji:JsonDocumentArray

Conversation

@roji
Copy link
Member

@roji roji commented Feb 22, 2026

Fixes #3677

Copilot AI review requested due to automatic review settings February 22, 2026 12:52
@roji roji enabled auto-merge (squash) February 22, 2026 12:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a regression introduced in version 10.0.0 where mapping arrays of JsonDocument or JsonElement to PostgreSQL jsonb[] columns would fail with an InvalidOperationException. The root cause was that NpgsqlJsonTypeMapping was unconditionally using JsonStringReaderWriter.Instance for all CLR types, but this reader/writer is specifically designed for string types and causes validation failures when used with JSON types like JsonDocument and JsonElement.

Changes:

  • Fixed NpgsqlJsonTypeMapping to only use JsonStringReaderWriter.Instance for string type, passing null for other types to allow EF Core to determine the appropriate reader/writer
  • Fixed error message formatting in NpgsqlArrayTypeMapping to correctly display type names
  • Added comprehensive test coverage for arrays and lists of JsonDocument and JsonElement

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/EFCore.PG/Storage/Internal/Mapping/NpgsqlJsonTypeMapping.cs Fixed constructor to conditionally assign JsonStringReaderWriter only for string types
src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs Fixed error message formatting bug (removed incorrect .GetType() call on Type object)
test/EFCore.PG.Tests/Storage/NpgsqlTypeMappingSourceTest.cs Added test coverage for JsonDocument/JsonElement arrays and lists; added System.Text.Json import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@roji roji merged commit e9528b4 into npgsql:main Feb 22, 2026
14 checks passed
@roji roji deleted the JsonDocumentArray branch February 22, 2026 13:03
roji added a commit that referenced this pull request Feb 22, 2026
@roji
Copy link
Member Author

roji commented Feb 22, 2026

Backported to 10.0.1 via 7bae265

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: arrays over JsonDocument/JsonElement don't work in 10.0.0

2 participants