Skip to content

Support System.Text.Json JsonElement in templates - #657

Merged
rexm merged 1 commit into
masterfrom
feat/issue-591-jsonelement-support
Aug 6, 2026
Merged

Support System.Text.Json JsonElement in templates#657
rexm merged 1 commit into
masterfrom
feat/issue-591-jsonelement-support

Conversation

@rexm

@rexm rexm commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds first-class support for System.Text.Json.JsonElement (the result of JsonSerializer.Deserialize<object>(json)) in templates: nested member access, {{#each}} iteration over both JSON objects and arrays, and correct {{#if}}/{{#unless}} truthiness — bringing it to parity with the existing Newtonsoft JObject/JToken support.
  • Reorganizes tests: folds the per-issue test files under source/Handlebars.Test/Issues/*.cs into the capability-based test files that already own that behavior (DynamicTests, PartialTests, HelperTests, BasicIntegrationTests, CustomConfigurationTests, HandlebarsSpecCoverageTests), and adds AGENTS.md documenting the convention so future regression tests land by capability instead of spawning new issue-numbered files.

Closes #591

Implementation

  • JsonElementMemberAccessor / JsonElementIterator / JsonElementObjectDescriptorProvider — plug into the existing IObjectDescriptorProvider pipeline the same way dictionary/dynamic/enumerable support already does.
  • HandlebarsUtils.IsFalsy/IsFalsyOrEmpty gain JSON-aware truthiness (false/null/""/0/empty array/empty object are falsy).
  • System.Text.Json package reference added for netstandard2.0/netstandard2.1 targets (net8.0 already ships it in the shared framework).
  • Scalar rendering (strings/numbers/nulls) needed no formatter changes — JsonElement.ToString() already produces correct text for those cases.

Test plan

  • dotnet build succeeds across netstandard2.0, netstandard2.1, and net8.0
  • dotnet test — 1904/1904 passing, no regressions
  • New coverage in DynamicTests.cs mirrors the existing JObject tests: nested property access, scalar rendering, array/object iteration, truthiness (true/false/empty string/null/0/empty array/empty object), missing-property handling

🤖 Generated with Claude Code

Untyped objects deserialized via System.Text.Json.JsonSerializer.Deserialize<object>
produce JsonElement, which previously had no member access, iteration, or truthiness
support, unlike Newtonsoft's JObject/JToken. Adds a JsonElementObjectDescriptorProvider
(member accessor + iterator) and teaches HandlebarsUtils.IsFalsy JSON truthiness
semantics so {{#if}}/{{#unless}} behave correctly on JsonElement values.

Also reorganizes tests: per-issue test files (source/Handlebars.Test/Issues/*.cs)
are folded into the capability-based test files that already cover that behavior,
and AGENTS.md documents the convention going forward so future test additions land
in the right place instead of spawning new issue-numbered files.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@rexm
rexm enabled auto-merge August 6, 2026 02:23
@sonarqubecloud

sonarqubecloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

@rexm
rexm merged commit 5570a4b into master Aug 6, 2026
7 checks passed
@rexm
rexm deleted the feat/issue-591-jsonelement-support branch August 6, 2026 02:35
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.

untyped objects deserialised by System.Text.Json are unsupprted

1 participant