velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nel Neliel <>
Subject Why HYPHEN is not propagated on Java Maps?
Date Mon, 15 Apr 2019 09:09:26 GMT

I have this template:
Slash: ${sample-slash}
Slash in a Map: ${map.sample-slash}

And I have this sample test case:

public class ApacheVelocityTest {
private final String RESOURCES_DIR = "src/test/resources";

public void testVelocity() {
Path templatePath = Paths.get(RESOURCES_DIR, "templates",

VelocityEngine ve = new VelocityEngine();
ve.setProperty(Velocity.PARSER_HYPHEN_ALLOWED, true);

Template t = ve.getTemplate(templatePath.toString());

VelocityContext context = new VelocityContext();

context.put("sample-slash", "SLASH");

Map<String, String> sampleData = createData();
context.put("map", sampleData);

StringWriter writer = new StringWriter();
t.merge(context, writer);


public Map<String, String> createData() {
Map<String, String> mapData = new HashMap<String, String>();

mapData.put("sample-slash", "USER1");

return mapData;


Now, the first "sample-slash" is rendered correctly but the one that is in
the config map is is throwing out an error like this:

org.apache.velocity.exception.ParseErrorException: Encountered "-slash}" at
src\test\resources\templates\[line 5, column 22]
Was expecting one of:
    "[" ...
    "|" ...
    "}" ...
    "}" ...

at org.apache.velocity.Template.process(

The parser exception is being thrown by the object that is embedded into
the java map.

Do I have any workaround for this developers?  Any pointers are greatly

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message