You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Onno Huijgen (Jira)" <ji...@apache.org> on 2025/05/09 14:02:00 UTC
[jira] [Created] (FREEMARKER-233) Using Freemarker in Native compiled app cannot handle POJO
Onno Huijgen created FREEMARKER-233:
---------------------------------------
Summary: 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
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)