title: How to access HashMap values in Freemarker where the key is an Integer
body: <p>I have a <code>HashMap&lt;Integer, String&gt;</code> called <code>lookup</code> that is provided by an Object I want to render in a Freemarker template.</p>
  
  <p>Here's the Java class:</p>
  
  <pre><code>public class SearchResultContainer implements Container&lt;T&gt; {
      private final Map&lt;Integer, String&gt; lookup;
      private final List&lt;T&gt; items;
  
      public SearchResultContainer(List&lt;T&gt; items, Map&lt;Integer, String&gt; lookup) {
          this.lookup= lookup;
          this.items = items;
      }
  
      @Override
      public List&lt;T&gt; getItems() {
          return items;
      }
  
      public Map&lt;Integer, String&gt; getLookup() {
          return this.lookup;
      }
  }
  </code></pre>
  
  <p>I tried to access the values of the map like this:</p>
  
  <pre><code>&lt;#-- @ftlvariable name="self" type="SearchResultContainer" --&gt;
  &lt;#assign lookup=self.lookup/&gt;
  &lt;#if lookup?has_content&gt;
    &lt;#list lookup?keys as key&gt;
      ${key} = ${lookup[key])}
    &lt;/#list&gt;
  &lt;#/if&gt;
  </code></pre>
  
  <p>I get this error: </p>
  
  <blockquote>
    <p>For "...[...]" left-hand operand: Expected a sequence or string or something automatically convertible to string (number, date or boolean), but this has evaluated to an extended_hash (HashMap wrapped into f.t.DefaultMapAdapter):<br>
    ==> lookup  [in template [...]<br>
    [...]<br>
    Tip: You had a numberical value inside the []. Currently that's only supported for sequences (lists) and strings. To get a Map item with a non-string key, use myMap?api.get(myKey).<br>
    [...]</p>
  </blockquote>
  
  <p>Then I tried to use <code>?api</code> as suggested:</p>
  
  <pre><code>&lt;#list lookup?keys as key&gt;
      ${key} = ${lookup?api.get(key)}
  &lt;/#list&gt;
  </code></pre>
  
  <p>And I get this error: </p>
  
  <blockquote>
    <p>Can't use ?api, because the "api_builtin_enabled" configuration setting is false. Think twice before you set it to true though. Especially, it shouldn't abused for modifying Map-s and Collection-s.<br>
    The blamed expression:<br>
    ==> lookup?api  [in template [...]</p>
  </blockquote>
  
  <p>Is there any other way to access the map, than to provide an additional method in my <code>SearchResultContainer</code> class, or enabling <code>api_builtin_enabled</code>, which is not suggested?</p>