freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "smforapache (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (FREEMARKER-90) Unable to parse keys of json having spaces
Date Sun, 18 Feb 2018 18:14:00 GMT

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

smforapache updated FREEMARKER-90:
----------------------------------
    Description: 
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.
<#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 ?


  was:
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.




> 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: Major
>         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.
> <#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)

Mime
View raw message