You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Aniruddha (Jira)" <ji...@apache.org> on 2021/08/04 15:59:00 UTC

[jira] [Closed] (FREEMARKER-185) eval_json fails

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

Aniruddha closed FREEMARKER-185.
--------------------------------
    Resolution: Not A Problem

Seems like it's not a bug. Found work around and proper implementation ways.

> eval_json fails
> ---------------
>
>                 Key: FREEMARKER-185
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-185
>             Project: Apache Freemarker
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 2.3.31
>            Reporter: Aniruddha
>            Priority: Major
>              Labels: features
>
>  
> {code:java}
> public static void main(String[] args) throws Throwable{
>         Configuration cfg = new Configuration(new Version("2.3.31"));
>         StringTemplateLoader stringLoader = new StringTemplateLoader();
>         cfg.setTemplateLoader(stringLoader);
>         StringBuilder sb = new StringBuilder();
>         sb.append("<#assign vals = '{  \"success\":true,  \"timestamp\":1627886463,  \"base\":\"Data1\",  \"date\":\"2021-08-02\",  \"values\":{    \"data2\":7.5,    \"data3\":44,    \"data4\":33  }}'?eval_json>");
>         sb.append("${vals}");
>         stringLoader.putTemplate("sample", sb.toString());
>         Map<String, Object> input = new HashMap<String, Object>();
>         Template template = cfg.getTemplate("sample");
>         Writer consoleWriter = new OutputStreamWriter(System.out);
>         template.process(input, consoleWriter);
>     }
> {code}
> The above code fails with below error
>  
>   FreeMarker template error (DEBUG mode; use RETHROW in production!):
>  For "${...}" content: Expected a string or something automatically convertible to string (number, date or boolean), or "template output" , but this has evaluated to an extended_hash (wrapper: f.t.SimpleHash):
>  ==> vals [in template "sample" at line 1, column 175]
> ----
> FTL stack trace ("~" means nesting-related):
>  - Failed at: ${vals} [in template "sample" at line 1, column 173]
> ----
> {{}}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)