You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Daniel Dekany (JIRA)" <ji...@apache.org> on 2018/02/21 13:27:00 UTC

[jira] [Closed] (FREEMARKER-90) Unable to parse keys of json having spaces

     [ https://issues.apache.org/jira/browse/FREEMARKER-90?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Dekany closed FREEMARKER-90.
-----------------------------------
    Resolution: Invalid

OK, then I close this as Invalid, as spaces in quoted keys are working, the problem was different.

> Unable to parse keys of json having spaces
> ------------------------------------------
>
>                 Key: FREEMARKER-90
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-90
>             Project: Apache Freemarker
>          Issue Type: Bug
>            Reporter: smforapache
>            Priority: Critical
>         Attachments: getSubCategories.ftl
>
>
> Facing issues while trying to parse JSON having keys with spaces in freemarkerĀ template.
> Sample JSONĀ :
> {
>  "response": {
>  "categories": {
>  "Daily Special": {},
>  "Main Course": {}
>  }
>  }
> }
> Attached the ftl file used to parse this.
> script in ftl which is failing where payLoad.category is Daily Special.
> <#assign subcategory_string = "response.categories."+"${payLoad.category}">
> <#assign subcategories = subcategory_string?eval>
> Exception :
> [WARN ] 2018-02-18 10:07:54.085 [asyncExecutor-3] TemplateBuilder - TemplateBuilder: Unable to substitute template
> freemarker.core._MiscTemplateException: Failed to "?eval" string with this error:
> ---begin-message---
> Syntax error in ?eval-ed string in line 1, column 40:
> Encountered "Special", but was expecting one of:
>     ".."
>     <DOT_DOT_LESS>
>     "..*"
>     ")"
>     "."
>     "["
>     "("
>     "?"
>     "!"
>     <TERMINATING_EXCLAM>
>     "??"
>     "+"
>     "-"
>     "*"
>     "/"
>     "%"
>     "!="
>     "="
>     "=="
>     ">="
>     <ESCAPED_GTE>
>     ">"
>     <ESCAPED_GT>
>     <LESS_THAN_EQUALS>
>     <LESS_THAN>
>     <AND>
>     <OR>
> ---end-message---
> The failing expression:
> ==> subcategory_string?eval  [in template "TEMPLATE" at line 10, column 26]
> ----
> FTL stack trace ("~" means nesting-related):
>         - Failed at: #assign subcategories = subcategory_s...  [in template "TEMPLATE" at line 10, column 1]
> ----
>         at freemarker.core.BuiltInsForStringsMisc$evalBI.calculateResult(BuiltInsForStringsMisc.java:70) ~[freemarker-2.3.23.jar!/:2.3.23]
>         at freemarker.core.BuiltInForString._eval(BuiltInForString.java:26) ~[freemarker-2.3.23.jar!/:2.3.23]
>         at freemarker.core.Expression.eval(Expression.java:78) ~[freemarker-2.3.23.jar!/:2.3.23]
>         at freemarker.core.Assignment.accept(Assignment.java:131) ~[freemarker-2.3.23.jar!/:2.3.23]
>         at freemarker.core.Environment.visit(Environment.java:324) ~[freemarker-2.3.23.jar!/:2.3.23]
>         at freemarker.core.MixedContent.accept(MixedContent.java:54) ~[freemarker-2.3.23.jar!/:2.3.23]
>         at freemarker.core.Environment.visit(Environment.java:324) ~[freemarker-2.3.23.jar!/:2.3.23]
>         at freemarker.core.Environment.process(Environment.java:302) ~[freemarker-2.3.23.jar!/:2.3.23]
>         at freemarker.template.Template.process(Template.java:325) ~[freemarker-2.3.23.jar!/:2.3.23]
> Is there any way to get out of this issue ?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)