Reputation: 559
I'm trying to print map's value bay key in FREEMARKER but got an exception
freemarker.core.NonStringException: Error on line 6, column 69 in internal_monitors.ftl
Expecting a string, date or number here, Expression object[key] is instead a freemarker.template.SimpleSequence
this is my code
<#if drives?exists>
<drives><#list drives as object>
<drive>
<#list object?keys as key>
<${key}><#if object[key]?exists>${object[key]}<#else>null</#if></${key}>
</#list>
</drive></#list>
</drives>
</#if>
any ideas ?
Upvotes: 0
Views: 3938
Reputation: 2924
Use ??
instead of ?exists
. The ?exists
built-in is deprecated.
You have to check, whether the object[key]
value is displayable (e.g. string, number, date, ...) or a container (hash, sequence). In the later case, you have either to skip it, or iterate its contents:
<#if drives??>
<#list drives as object>
<drive>
<#list drive?keys as key>
<${key}>
<#if object[key]??>
<#if object[key]?is_hash>
HASH
<#elseif object[key]?is_sequence>
SEQUENCE
<#else>
${object[key]}
</#if>
<#else>
null
</#if>
</${key}>
</#list>
</drive>
</#list>
</#if>
Upvotes: 1