[
https://issues.apache.org/jira/browse/FREEMARKER-233?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Onno Huijgen closed FREEMARKER-233.
-----------------------------------
Resolution: Information Provided
> Using Freemarker in Native compiled app cannot handle POJO
> ----------------------------------------------------------
>
> Key: FREEMARKER-233
> URL: https://issues.apache.org/jira/browse/FREEMARKER-233
> Project: Apache Freemarker
> Issue Type: Bug
> Components: engine
> Affects Versions: 2.3.32
> Reporter: Onno Huijgen
> Priority: Minor
>
> Processing Freemarker templates from {{public static void main}} works as
> expected:
>
> {{template.process(root, output);}}
>
> Given this POJO class
> {code:java}
> public class Code {
> private String groupId;
> private String artifactId;
> private String version;
> ...
> // getters/setters
> ...
> }{code}
> and an object
> # root as Map<String, Object>
> # root as Map<String, Object> with Code also as Map<String, Object> (map in
> map)
> # root with map.put("code", Code) (object in map)
> # root as Code
> all yield in a proper rendered template.
> After native compilation however options 3 and 4 (using the Code object) do
> not work:
> {code:java}
> Caused by: freemarker.core.InvalidReferenceException: The following has
> evaluated to null or missing:==> code.groupId [in template
> "templates/java/micronaut/pom.xml.ftl" at line 6, column 16]
> ----Tip: It's the step after the last dot that caused this error, not those
> before it.----Tip: If the failing expression is known to legally refer to
> something that's sometimes null or missing, either specify a default value
> like myOptionalVar!myDefault, or use <#if
> myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the
> last step of the expression; to cover the whole expression, use parenthesis:
> (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??----
> ----FTL stack trace ("~" means nesting-related): - Failed at:
> ${code.groupId} [in template "templates/java/micronaut/pom.xml.ftl" at line
> 6, column 14]---- {code}
> Any suggestions on how to fix this are welcome ;-)
> Workaround for now of course is just to populate one or more maps and not use
> POJOs, but it's a bit unexpected.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)