Since 2.3.25, do it like this:
<#list user as propName, propValue>
${propName} = ${propValue}
</#list>
Note that this also works with non-string keys (unlike map[key]
, which had to be written as map?api.get(key)
then).
Before 2.3.25 the standard solution was:
<#list user?keys as prop>
${prop} = ${user[prop]}
</#list>
However, some really old FreeMarker integrations use a strange configuration, where the public Map
methods (like getClass
) appear as keys. That happens as they are using a pure BeansWrapper
(instead of DefaultObjectWrapper
) whose simpleMapWrapper
property was left on false
. You should avoid such a setup, as it mixes the methods with real Map
entries. But if you run into such unfortunate setup, the way to escape the situation is using the exposed Java methods, such as user.entrySet()
, user.get(key)
, etc., and not using the template language constructs like ?keys
or user[key]
.