Skip to content

JsonNodeValueResolver: resolve Map contexts (block parameters) (#983) - #1229

Merged
jknack merged 1 commit into
jknack:masterfrom
amalsaidov:fix/jsonnode-resolve-map-983
Nov 30, 2026
Merged

jknack merged 1 commit into
jknack:masterfrom
amalsaidov:fix/jsonnode-resolve-map-983

Conversation

@amalsaidov

Copy link
Copy Markdown
Contributor

JsonNodeValueResolver only handled JsonNode/ArrayNode contexts. When a plain Map is pushed on the context stack — which is how {{#each xs as |value index|}} block parameters are stored — the resolver returned UNRESOLVED for every key, and propertySet returned an empty set.

End-to-end templates still rendered because Context.Builder#resolver(...) appends MapValueResolver, so the Map was resolved by that fallback. But the resolver on its own could not look up a Map, which is what #983 reports.

This mirrors MapValueResolver's Map handling inside JsonNodeValueResolver for resolve(context, name), resolve(context) and propertySet(context), so block parameters resolve even when JsonNodeValueResolver is used without MapValueResolver.

The same fix is applied to both the Jackson 2 (handlebars-jackson) and Jackson 3 (handlebars-jackson3) resolvers, since they are kept in parallel.

Testing

Added a resolveMap unit test to each module's JsonNodeValueResolverTest. Before the change it fails (expected: <0> but was: <...UNRESOLVED...>); after it passes. mvn test is green for handlebars-jackson, handlebars-jackson3 and tests (50 tests), and spotless:check passes with no new offenses.

Fixes #983

Happy to adjust the approach if you'd prefer to resolve the Map values through JsonNode resolution instead of returning them as-is.

JsonNodeValueResolver only handled JsonNode/ArrayNode contexts, so when a
plain Map was pushed on the context stack (as each-block parameters are) it
returned UNRESOLVED. End-to-end templates still worked because the context
builder appends MapValueResolver, but the resolver itself could not look up a
Map on its own.

Handle Map contexts the same way MapValueResolver does in resolve(context,
name), resolve(context) and propertySet(context). Applied to both the Jackson 2
and Jackson 3 resolvers, with a unit test for each.

Fixes jknack#983

Signed-off-by: karma <inskarma0101@gmail.com>

@jknack jknack left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you

@jknack jknack added the bug label Nov 30, 2026
@jknack jknack added this to the 4.6.0 milestone Nov 30, 2026
@jknack
jknack merged commit 75294c0 into jknack:master Nov 30, 2026
2 checks passed
@amalsaidov

Copy link
Copy Markdown
Contributor Author

Thanks for merging 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JsonNodeValueResolver does not resolve block parameters correctly

2 participants