Support System.Text.Json JsonElement in templates - #657
Merged
Conversation
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
enabled auto-merge
August 6, 2026 02:23
|
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.



Summary
System.Text.Json.JsonElement(the result ofJsonSerializer.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 NewtonsoftJObject/JTokensupport.source/Handlebars.Test/Issues/*.csinto the capability-based test files that already own that behavior (DynamicTests,PartialTests,HelperTests,BasicIntegrationTests,CustomConfigurationTests,HandlebarsSpecCoverageTests), and addsAGENTS.mddocumenting 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 existingIObjectDescriptorProviderpipeline the same way dictionary/dynamic/enumerable support already does.HandlebarsUtils.IsFalsy/IsFalsyOrEmptygain JSON-aware truthiness (false/null/""/0/empty array/empty object are falsy).System.Text.Jsonpackage reference added fornetstandard2.0/netstandard2.1targets (net8.0already ships it in the shared framework).JsonElement.ToString()already produces correct text for those cases.Test plan
dotnet buildsucceeds acrossnetstandard2.0,netstandard2.1, andnet8.0dotnet test— 1904/1904 passing, no regressionsDynamicTests.csmirrors the existingJObjecttests: 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