jluce50
jluce50

Reputation: 1203

Apache Velocity: Escape character not working

I'm using Velocity to generate java code and I'm running into a problem with the following line in the template:

return Marshal$sdo.getName().dynamicSize(this);

with the desired output being:

return MarshalSomeClass.dynamicSize(this);

In this case the VLT is limited to "$sdo.getName()" but the trailing "." causes it not to evaluate the VLT portion.

When I try to escape the "." (e.g. $sdo.getName()\.dynamicSize) I get the following output:

return MarshalTestTypesFile\.dynamicSize(this);

I've tried assigning the "." to a VLT variable and wrapping it with curly braces, but then the curly braces are printed. I've tried {$sdo.getName()} and have the same problem. I've tried all the other tricks for escaping to no avail. Seems like it should be pretty simple, but I'm stumped. What am I missing here?

Upvotes: 2

Views: 1624

Answers (1)

Guillaume Polet
Guillaume Polet

Reputation: 47608

Simply use the formal VTL notation with the braces:

return Marshal${sdo.getName()}.dynamicSize(this);

Upvotes: 4

Related Questions