I have java.lang.Iterable (in fact, an instance of com.google.gson.JsonArray).
I would like to list the items in a list using freemarker (2.3.16).
[#assign sports = controller.sports] [
I would like to avoid having to write a custom bean and Gson handle to have an explicit set of elements. Using Gson (which already deserializes the JSON string for JsonObject for me) to then create my own DAG of objects from this JsonObject seems to me wasteful.
Unfortunately, I could not find a way to get Freemarker to treat java.lang.Iterable as a list. I get:
freemarker.template.TemplateException : Expected collection or sequence. controller.sports evaluated instead to freemarker.ext.beans.XMLStringModel on line 8, column 16 in sports.html. freemarker.core.TemplateObject.invalidTypeException(line:135) freemarker.core.IteratorBlock$Context.runLoop(line:190) freemarker.core.Environment.visit(line:417) freemarker.core.IteratorBlock.accept(line:102) freemarker.core.Environment.visit(line:210)
source share