title: Returning list from Java to Freemarker
body: <p>I've searched through these questions and found that you can return lists and call Java object methods from within Freemarker, however I've not been able to get it to work. I've tried calling the method from the object method and using the method implemented using the TemplateMethodModelEx class.</p>
  
  <p>This is my Freemarker:</p>
  
  <pre><code>&lt;#assign relations&gt;
         ${filterStationRelationships(record.relationships, [1,22,23])}
  &lt;/#assign&gt;
  
  &lt;relationships&gt;
      &lt;#list relations as rel&gt;
      &lt;relationship type="${rel.name}"&gt;${rel.sourceId1!"NO STATION"}&lt;/relationship&gt;
      &lt;/#list&gt;
  &lt;/relationships&gt;
  </code></pre>
  
  <p>Here is my Java (actually Groovy):</p>
  
  <pre><code>@BoundClass(bindingName="filterStationRelationships")
  class FilterStationRelationships implements TemplateMethodModelEx {
  
  @Override
  public List&lt;StationRelationship&gt; exec(List args) throws TemplateModelException {
      if (args.size() != 2) {
          throw new TemplateModelException('FilterStationRelationships needs two arguments')
      }
      List&lt;StationRelationship&gt; stationRels = (List&lt;StationRelationship&gt;)DeepUnwrap.unwrap(args[0])
      List&lt;Integer&gt; typeIds = (List&lt;Integer&gt;)DeepUnwrap.unwrap(args[1])
  
      Map map = new HashMap();
  
      stationRels.findAll { rel -&gt;
          typeIds.contains(rel.typeId)
      }
  
  }
  
  }
  </code></pre>
  
  <p>I've verified that the args are valid inside the Groovy, but when it sends the List back to Freemarker, I get this:</p>
  
  <pre><code>&lt;relationships&gt;
  </code></pre>
  
  <p>Expected collection or sequence. relations evaluated instead to freemarker.template.SimpleScalar on line 24, column 24 in default-groovy-template.
  The problematic instruction:</p>
  
  <p>==> list relations as rel [on line 24, column 17 in default-groovy-template]</p>
  
  <p>Any ideas?</p>