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/18 20:03:00 UTC
[jira] [Commented] (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:comment-tabpanel&focusedCommentId=16368658#comment-16368658 ]
Daniel Dekany commented on FREEMARKER-90:
-----------------------------------------
I can't reproduce this. For me, {{?eval}} has no problem with quoted names that contains space. Can you give a minimal but complete example? It can be just pure FTL, that you can try on http://try.freemarker.org/.
> 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)