Skip to content

Support System.Text.Json serialization of LTree - #4006

Merged
roji merged 1 commit into
mainfrom
roji-issue-3538-triage
Oct 18, 2026
Merged

roji merged 1 commit into
mainfrom
roji-issue-3538-triage

Conversation

@roji

@roji roji commented Oct 18, 2026

Copy link
Copy Markdown
Member

System.Text.Json currently attempts to read LTree's server-only NLevel property, causing serialization to throw even when no EF query is involved.

Attach a string-valued JSON converter to LTree so standalone values and DTO properties serialize and deserialize without application-level registration. Query-only members continue to throw outside queries. The converter is public and nested to support source-generated JSON contexts.

Includes coverage for standalone values, DTO properties, empty/default values, nullable values, and source-generated serialization.

Fixes #3538

Add a type-level string converter without changing query-only operations. Make the converter public for source-generated JSON contexts.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: be699e8c-b6bd-4df1-9e12-8884e2e6f945
Copilot AI balanced review requested due to automatic review settings October 18, 2026 09:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The localized change has focused regression coverage and no identified blocking issues; tests were not executed.

No open issues 🎉

What changed in this PR

Adds built-in System.Text.Json support for LTree, avoiding access to query-only properties during serialization and addressing #3538.

Changes:

  • Registers a public nested converter for string-valued JSON serialization.
  • Adds coverage for standalone values, DTO properties, empty/default and nullable values, source generation, and query-only behavior.
File Description
test/​EFCore.PG.Tests/​Types/​LTreeTest.cs Adds serialization and query-only behavior regression tests.
src/​EFCore.PG/​Types/​LTree.cs Adds and registers the JSON converter.

Review effort: Balanced

@roji
roji merged commit aead2ab into main Oct 18, 2026
16 checks passed
@roji
roji deleted the roji-issue-3538-triage branch October 18, 2026 10:14
roji added a commit that referenced this pull request Oct 18, 2026
Backport #4006 to hotfix/10.0.4.

(cherry picked from commit aead2ab)

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 4200d70c-76b3-4098-8891-5403ef70962f
roji added a commit that referenced this pull request Oct 18, 2026
Backport #4006 (aead2ab) to hotfix/9.0.5 without changes.

Fixes #3538

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 10dee5d2-a38d-474a-9454-546470abbd84
roji added a commit that referenced this pull request Oct 18, 2026
Backport #4006 to hotfix/8.0.12.

(cherry picked from commit aead2ab)

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: d8d8a304-ae5a-4349-bf84-37751d55433c
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.

Serializing an LTree value to a JSON string results in an exception

2 participants