Fix JsonNode[] missing from basic JSON types#6549
Merged
Merged
Conversation
- 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
…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]>
…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]>
There was a problem hiding this comment.
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
JsonNodesupport toBasicJsonTypeInfoResolverso defaultJsonSerializerOptionscan resolve metadata forJsonNode. - Add array mapping for
JsonNode(AddArrayType<JsonNode>) soJsonNode[]can map tojson[]/jsonb[]. - Add/keep a
Roundtrip_JsonNoderegression 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
pushed a commit
that referenced
this pull request
Apr 21, 2026
(cherry picked from commit 2d91c29)
Member
|
Backported to 10.0.3 via 62a2f37 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JsonNodetoBasicJsonTypeInfoResolver(new)AddArrayType<JsonNode>toArrayResolver(new)Roundtrip_JsonNodetest