title: How to call reflection methods in freemarker template?
body: <p>We can iterate over class fields, annotations with some code like this in java:</p>
  
  <pre><code>Class&lt;?&gt; clazz;
  for(Field field : clazz.getDeclaredFields()) {
      for(Annotation annotation : field.getDeclaredAnnotations()) {
          for(Method method : annotation.annotationType().getMethods()) {
              if(method.getName().equals("nullable")) {
                  try {
                      // note this line
                      System.out.println(method.invoke(annotation, (Object[])null) );
                  }
                  catch(Exception e) {
                      System.out.println("Ex");
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>above codes want to check that if one of annotations of fields have <code>nullable</code> method, log it's value. assume this field  some class:</p>
  
  <pre><code>public class someClass {
      @Column(nullable = false)
      private Long number;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "entity_id", nullable = true)
      private Entity entity;
  }
  </code></pre>
  
  <p>That above code for this class logs <code>false</code>, then <code>true</code> as a value of <code>nullable</code> attribute in field annotations. Now i want to iterate over class fields and annotations in freemarker template, but the problem is that i cant call <code>method.invoke(annotation, (Object[])null)</code>.</p>
  
  <pre><code>&lt;#list fields as field&gt;
      &lt;#list field.annotations as annotation&gt;
          &lt;#if annotation??&gt;
              &lt;#if annotation.annotationType().getSimpleName() == "Column" || annotation.annotationType().getSimpleName() == "JoinColumn"&gt;
                  &lt;#list annotation.annotationType().getMethods() as annotationMethod&gt;
                      &lt;#attempt&gt;
                          &lt;#if annotationMethod.getName() == "nullable"&gt;
                              // this line get error 
                              ${annotationMethod.invoke(annotation, (Object[])null)}
                          &lt;/#if&gt;
                          &lt;#recover&gt;
                      &lt;/#attempt&gt;
                  &lt;/#list&gt;
                  &lt;#break&gt;
              &lt;/#if&gt;
          &lt;/#if&gt;
      &lt;/#list&gt;
  &lt;/#list&gt;
  </code></pre>
  
  <p>Is there another way to achieve this goal in freemarker template?
  I want to use these code for code generator.</p>
  
  <p><strong>UDPATE</strong></p>
  
  <p>this is the exception that i gave:</p>
  
  <pre><code>Syntax error in template "entity-detail.ftl" in line 32, column 111:
  Encountered "]", but was expecting one of:
      &lt;STRING_LITERAL&gt;
      &lt;RAW_STRING&gt;
      "false"
      "true"
      &lt;INTEGER&gt;
      &lt;DECIMAL&gt;
      "."
      "+"
      "-"
      "!"
      "["
      "("
      "{"
      &lt;ID&gt;
  freemarker.core.ParseException: Syntax error in template "entity-detail.ftl" in line 32, column 111:
  Encountered "]", but was expecting one of:
      &lt;STRING_LITERAL&gt;
      &lt;RAW_STRING&gt;
      "false"
      "true"
      &lt;INTEGER&gt;
      &lt;DECIMAL&gt;
      "."
      "+"
      "-"
      "!"
      "["
      "("
      "{"
      &lt;ID&gt;
      at freemarker.core.FMParser.generateParseException(FMParser.java:5749)
      at freemarker.core.FMParser.jj_consume_token(FMParser.java:5608)
      at freemarker.core.FMParser.UnaryExpression(FMParser.java:658)
      at freemarker.core.FMParser.MultiplicativeExpression(FMParser.java:768)
      at freemarker.core.FMParser.AdditiveExpression(FMParser.java:720)
      at freemarker.core.FMParser.RangeExpression(FMParser.java:900)
      at freemarker.core.FMParser.RelationalExpression(FMParser.java:848)
      at freemarker.core.FMParser.EqualityExpression(FMParser.java:811)
      at freemarker.core.FMParser.AndExpression(FMParser.java:967)
      at freemarker.core.FMParser.OrExpression(FMParser.java:989)
      at freemarker.core.FMParser.Expression(FMParser.java:548)
      at freemarker.core.FMParser.DynamicKey(FMParser.java:1341)
      at freemarker.core.FMParser.AddSubExpression(FMParser.java:1107)
      at freemarker.core.FMParser.PrimaryExpression(FMParser.java:607)
      at freemarker.core.FMParser.UnaryExpression(FMParser.java:653)
      at freemarker.core.FMParser.MultiplicativeExpression(FMParser.java:768)
      at freemarker.core.FMParser.AdditiveExpression(FMParser.java:720)
      at freemarker.core.FMParser.RangeExpression(FMParser.java:900)
      at freemarker.core.FMParser.RelationalExpression(FMParser.java:848)
      at freemarker.core.FMParser.EqualityExpression(FMParser.java:811)
      at freemarker.core.FMParser.AndExpression(FMParser.java:967)
      at freemarker.core.FMParser.OrExpression(FMParser.java:989)
      at freemarker.core.FMParser.Expression(FMParser.java:548)
      at freemarker.core.FMParser.Parenthesis(FMParser.java:616)
      at freemarker.core.FMParser.PrimaryExpression(FMParser.java:588)
      at freemarker.core.FMParser.UnaryExpression(FMParser.java:653)
      at freemarker.core.FMParser.MultiplicativeExpression(FMParser.java:768)
      at freemarker.core.FMParser.AdditiveExpression(FMParser.java:720)
      at freemarker.core.FMParser.RangeExpression(FMParser.java:900)
      at freemarker.core.FMParser.RelationalExpression(FMParser.java:848)
      at freemarker.core.FMParser.EqualityExpression(FMParser.java:811)
      at freemarker.core.FMParser.AndExpression(FMParser.java:967)
      at freemarker.core.FMParser.OrExpression(FMParser.java:989)
      at freemarker.core.FMParser.Expression(FMParser.java:548)
      at freemarker.core.FMParser.PositionalArgs(FMParser.java:2985)
      at freemarker.core.FMParser.MethodArgs(FMParser.java:1357)
      at freemarker.core.FMParser.AddSubExpression(FMParser.java:1111)
      at freemarker.core.FMParser.PrimaryExpression(FMParser.java:607)
      at freemarker.core.FMParser.UnaryExpression(FMParser.java:653)
      at freemarker.core.FMParser.MultiplicativeExpression(FMParser.java:768)
      at freemarker.core.FMParser.AdditiveExpression(FMParser.java:720)
      at freemarker.core.FMParser.RangeExpression(FMParser.java:900)
      at freemarker.core.FMParser.RelationalExpression(FMParser.java:848)
      at freemarker.core.FMParser.EqualityExpression(FMParser.java:811)
      at freemarker.core.FMParser.AndExpression(FMParser.java:967)
      at freemarker.core.FMParser.OrExpression(FMParser.java:989)
      at freemarker.core.FMParser.Expression(FMParser.java:548)
      at freemarker.core.FMParser.StringOutput(FMParser.java:1522)
      at freemarker.core.FMParser.MixedContentElements(FMParser.java:3721)
      at freemarker.core.FMParser.If(FMParser.java:1625)
      at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:3384)
      at freemarker.core.FMParser.MixedContentElements(FMParser.java:3772)
      at freemarker.core.FMParser.Attempt(FMParser.java:1671)
      at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:3511)
      at freemarker.core.FMParser.MixedContentElements(FMParser.java:3772)
      at freemarker.core.FMParser.List(FMParser.java:1746)
      at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:3388)
      at freemarker.core.FMParser.MixedContentElements(FMParser.java:3772)
      at freemarker.core.FMParser.If(FMParser.java:1625)
      at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:3384)
      at freemarker.core.FMParser.MixedContentElements(FMParser.java:3772)
      at freemarker.core.FMParser.If(FMParser.java:1625)
      at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:3384)
      at freemarker.core.FMParser.MixedContentElements(FMParser.java:3772)
      at freemarker.core.FMParser.List(FMParser.java:1746)
      at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:3388)
      at freemarker.core.FMParser.MixedContentElements(FMParser.java:3772)
      at freemarker.core.FMParser.Attempt(FMParser.java:1671)
      at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:3511)
      at freemarker.core.FMParser.MixedContentElements(FMParser.java:3772)
      at freemarker.core.FMParser.List(FMParser.java:1746)
      at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:3388)
      at freemarker.core.FMParser.MixedContentElements(FMParser.java:3772)
      at freemarker.core.FMParser.Root(FMParser.java:4411)
      at freemarker.template.Template.&lt;init&gt;(Template.java:252)
      at freemarker.cache.TemplateCache.loadTemplate(TemplateCache.java:549)
      at freemarker.cache.TemplateCache.getTemplateInternal(TemplateCache.java:439)
      at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:292)
      at freemarker.template.Configuration.getTemplate(Configuration.java:2654)
      at freemarker.template.Configuration.getTemplate(Configuration.java:2503)
      at com.vira.framework.common.generator.CodeGenerator.generate(CodeGenerator.java:70)
      at com.vira.framework.common.generator.CodeGeneratorTest.main(CodeGeneratorTest.java:7)
  </code></pre>