jknack / handlebars.java

Logic-less and semantic Mustache templates with Java
http://jknack.github.io/handlebars.java
Other
1.48k stars 383 forks source link

Each helper throws "java.lang.ClassCastException" when Map key is not a string #524

Closed dudabone closed 8 years ago

dudabone commented 8 years ago

Not sure that this is a bug - but when passing a Map<Long, V> in the context and iterating with {{#each}}, I get the following exception:

om.github.jknack.handlebars.HandlebarsException: /resources/app/templates/forms/bindable-controls/bindable-single-select.hbs:4:11: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String /resources/app/templates/forms/bindable-controls/bindable-single-select.hbs:4: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)

Is it supposed to be like this? are map keys limited only to Strings?

dudabone commented 8 years ago

Sorry, correction - this happens because the values of the map are of custom class of ours: SourceResult <K, V>. In this case, K is of type Long, and this is where the exception is thrown (EachHelper.java:89):

String key = entry.getKey();

Is there anything to do in order to support this or must I change it to SourceResult<String, String>?

dudabone commented 8 years ago

Ok, just noticed that this issue was fixed in https://github.com/jknack/handlebars.java/commit/9809123b33cf894da84bdebbfa94f39b0bc5736d.

Amazing :)

closing the issue

jknack commented 8 years ago

Duplicate #502

It was! :)

I invite you to try: http://jooby.org