Skip to content

Fix JsonNode[] missing from basic JSON types#6549

Merged
NinoFloris merged 8 commits into
mainfrom
copilot/add-jsonnode-array-mapping
Apr 21, 2026
Merged

Fix JsonNode[] missing from basic JSON types#6549
NinoFloris merged 8 commits into
mainfrom
copilot/add-jsonnode-array-mapping

Conversation

Copilot AI commented Apr 20, 2026

Copy link
Copy Markdown
Contributor
  • Investigate CI failures and understand root cause
  • Understand original file state before PR
  • Revert JsonTypeInfoResolverFactory.cs to pre-PR state (restore separate subtype mappings)
  • Add JsonNode to BasicJsonTypeInfoResolver (new)
  • Add AddArrayType<JsonNode> to ArrayResolver (new)
  • Keep Roundtrip_JsonNode test
  • Build and validate

Copilot AI linked an issue Apr 20, 2026 that may be closed by this pull request
- Add TypeMatchPredicate to JsonNode mapping to match all JsonNode descendants
- Move JsonNode mapping after specific subtypes so exact matches are preferred
- Add AddArrayType<JsonNode> to ArrayResolver for array support
- Add JsonNode to BasicJsonTypeInfoResolver via JsonMetadataServices.JsonNodeConverter
- Add Roundtrip_JsonNode regression test using AssertType infra

Agent-Logs-Url: https://github.com/npgsql/npgsql/sessions/4575ad49-1f92-4d2d-8b73-36326513d61f

Co-authored-by: NinoFloris <[email protected]>
Copilot AI changed the title [WIP] Add mapping for JsonNode[] in JsonTypeInfoResolverFactory Fix JsonNode[] missing from basic JSON types Apr 20, 2026
Copilot AI requested a review from NinoFloris April 20, 2026 15:59
…morphic mapping

Remove redundant JsonObject/JsonArray/JsonValue element and array mappings.
A single JsonNode mapping with TypeMatchPredicate using IsAssignableFrom
handles all descendants — STJ's JsonNodeConverter already provides
polymorphic serialization/deserialization. The per-subtype mappings were
redundant, and their incompleteness (missing JsonNode itself) caused #6517.

Agent-Logs-Url: https://github.com/npgsql/npgsql/sessions/d45599d8-a2e0-4925-809a-a5e72f264554

Co-authored-by: NinoFloris <[email protected]>
Copilot AI and others added 3 commits April 20, 2026 16:22
…ngle

Uses the IPAddress pattern for the JsonNode mapping:
- PgConcreteTypeInfo with unboxedType for subtypes so TypeInfoCache
  type checks pass when resolving JsonObject/JsonArray/JsonValue
- MatchRequirement.Single to enable data type inference from CLR type
- No type-is-null in predicate since string is the default for json/jsonb

Agent-Logs-Url: https://github.com/npgsql/npgsql/sessions/ac6c2e00-45a3-439c-bbdf-cc71c2ca5698

Co-authored-by: NinoFloris <[email protected]>
…ping

MatchRequirement.All handles type-only lookups via the fallback mechanism
in Find(). The unboxedType pattern is sufficient to make TypeInfoCache
type checks pass for JsonNode subtypes.

Agent-Logs-Url: https://github.com/npgsql/npgsql/sessions/ac6c2e00-45a3-439c-bbdf-cc71c2ca5698

Co-authored-by: NinoFloris <[email protected]>
…=true

Use unboxedType pattern with SupportsReading override instead of separate
subtype mappings. STJ's JsonNodeConverter handles polymorphic
serialization/deserialization for all JsonNode descendants.

- Remove type-is-null from predicate (string is the default for json/jsonb)
- Use MatchRequirement.All (default) for fallback-based type matching
- Set SupportsReading=true since JsonNode converter can read subtypes

Agent-Logs-Url: https://github.com/npgsql/npgsql/sessions/a2c4c12d-31b2-488d-83a4-d2581ae0494b

Co-authored-by: NinoFloris <[email protected]>
…r and AddArrayType<JsonNode>

Reverts all previous attempts at refactoring the JsonNode mapping.
The minimal fix for issue #6517 is just two additions:
1. JsonNode entry in BasicJsonTypeInfoResolver for STJ type resolution
2. AddArrayType<JsonNode> in ArrayResolver for JsonNode[] support

Agent-Logs-Url: https://github.com/npgsql/npgsql/sessions/ad6932b5-fdee-47b7-bdfd-b210b8407a46

Co-authored-by: NinoFloris <[email protected]>
@NinoFloris
NinoFloris marked this pull request as ready for review April 20, 2026 20:08
@NinoFloris
NinoFloris requested a review from roji as a code owner April 20, 2026 20:08
Copilot AI review requested due to automatic review settings April 20, 2026 20:08
@NinoFloris
NinoFloris requested a review from vonzshik as a code owner April 20, 2026 20:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes missing JsonNode/JsonNode[] support in Npgsql’s “basic” System.Text.Json type handling to address CI/runtime failures around JSON type resolution.

Changes:

  • Add JsonNode support to BasicJsonTypeInfoResolver so default JsonSerializerOptions can resolve metadata for JsonNode.
  • Add array mapping for JsonNode (AddArrayType<JsonNode>) so JsonNode[] can map to json[]/jsonb[].
  • Add/keep a Roundtrip_JsonNode regression test.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/Npgsql.Tests/Types/JsonTests.cs Adds a JsonNode roundtrip test to validate scalar behavior and inference.
src/Npgsql/Internal/ResolverFactories/JsonTypeInfoResolverFactory.cs Extends resolver mappings to include JsonNode and JsonNode[] in basic JSON type resolution.

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

@NinoFloris
NinoFloris merged commit 2d91c29 into main Apr 21, 2026
21 checks passed
@NinoFloris
NinoFloris deleted the copilot/add-jsonnode-array-mapping branch April 21, 2026 15:52
NinoFloris pushed a commit that referenced this pull request Apr 21, 2026
@NinoFloris

Copy link
Copy Markdown
Member

Backported to 10.0.3 via 62a2f37

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.

JsonNode[] missing from basic JSON types.

3 participants