It appears that when trying to iterate over a Map with non-string keys (e.g. Map<Object,Object>) we get an ClassCastException
java.lang.ClassCastException: com.xyz.ObjectGroup cannot be cast to java.lang.String
inline@c686e86:94:11
at com.github.jknack.handlebars.helper.EachHelper.apply(EachHelper.java:89)
at com.github.jknack.handlebars.internal.Block.merge(Block.java:211)
at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128)
at com.github.jknack.handlebars.internal.TemplateList.merge(TemplateList.java:94)
at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128)
The following code demonstrates the problem:
Map<Object,Collection<String>> data = new TreeMap<>();
Collection<String> d1 = new ArrayList<>();
d1.add("1");
d1.add("2");
d1.add("3");
Collection<String> d2 = new ArrayList<>();
d2.add("4");
d2.add("5");
d2.add("6");
data.put(123, d1);
data.put(456, d2);
Map<String,Object> params = new HashMap<>();
params.put("data", data);
String result = new Handlebars().compileInline( "{{#each data}}{{ @key }} - {{#each . }}Val:{{.}}{{/each}}{{/each}}").apply(params);`
Is there a reason this is not supported as the code changes required to support it look trivial
It appears that when trying to iterate over a Map with non-string keys (e.g. Map<Object,Object>) we get an ClassCastException
java.lang.ClassCastException: com.xyz.ObjectGroup cannot be cast to java.lang.String inline@c686e86:94:11 at com.github.jknack.handlebars.helper.EachHelper.apply(EachHelper.java:89) at com.github.jknack.handlebars.internal.Block.merge(Block.java:211) at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128) at com.github.jknack.handlebars.internal.TemplateList.merge(TemplateList.java:94) at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128)
The following code demonstrates the problem:
Is there a reason this is not supported as the code changes required to support it look trivial