Skip to content

JsonNodeValueResolver should unwrap Jackson2 ArrayNode  #964

@carusology

Description

@carusology

Background

When you attempt to render a Handlebars template with ...

  1. The JsonNodeValueResolver configured as a resolver
  2. A Jackson2 JsonNode as your context
  3. A helper that expects an Iterable

... the helper will be provided a raw ArrayNode instead of an Iterable with its JsonNode items recursively resolved. This causes surprising behavior when writing an iterable-based helpers because in all other situations the JsonNodeValueResolver resolves the JsonNode objects into their idiomatic Java types. For example, the BooleanNode is resolved as a boolean, the NullNode as null, and the ObjectNode as a Map<String, Object> (Source). The ArrayNode, however, is kept as an ArrayNode as it undergoes resolution (Source).

To see the effect of this inconsistency, consider the following context:

{ "pets": [ "dog", "cat", "bird" ] }

If we pass this.pets into the join helper using property accessors like so ...

{{ join this.pets.[0] this.pets.[1] this.pets.[2] ", " }}

... we get unsurprising and predictable output: dog, cat, bird.

However, if we pass in the ArrayNode to the helper directly like so ...

{{ join this.pets ", " }}

... we get the surprising output: "dog", "cat", "bird" (note the quotes encapsulating each item). If the JsonNodeValueResolver unwrapped the ArrayNode like it did the ObjectNode into its idiomatic Java type, the behavior of the join helper would be consistent whether we pass in items from arrays via property accessors or as an Iterable.

Task

Update the JsonNodeValueResolver to resolve each ArrayNode as a List<Object> with recursively resolved items, just like it does for an ObjectNode into a Map<String, Object> with recursively resolved values (Source).

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions