forked from jknack/handlebars.java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recursively resolve JSON Object nodes during entry iteration (jknack#969
- Loading branch information
1 parent
881bd24
commit 0b94900
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
33 changes: 33 additions & 0 deletions
33
handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue969.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.jknack.handlebars; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.jknack.handlebars.context.MapValueResolver; | ||
import com.github.jknack.handlebars.helper.StringHelpers; | ||
|
||
import org.junit.Test; | ||
|
||
public class Issue969 extends AbstractTest { | ||
|
||
@Override | ||
protected Object configureContext(final Object model) { | ||
return Context.newBuilder(model) | ||
.resolver(MapValueResolver.INSTANCE, JsonNodeValueResolver.INSTANCE) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected Handlebars newHandlebars() { | ||
return super.newHandlebars().with(EscapingStrategy.NOOP); | ||
} | ||
|
||
@Test | ||
public void shouldRecursivelyResolveEntries() throws IOException { | ||
Hash helpers = $("join", StringHelpers.join); | ||
JsonNode tree = new ObjectMapper().readTree("{\"pets\":[{\"type\":\"cat\",\"name\":\"alice\"},{\"type\":\"bird\",\"name\":\"bob\"}]}"); | ||
shouldCompileTo("{{join this.pets \", \"}}", tree, helpers, "{type=cat, name=alice}, {type=bird, name=bob}"); | ||
} | ||
|
||
} |