Is there a way to render a template from a map containing a key with a dot character ?
def config = '''
person {
name = "foo"
}
'''
def flat_config_map = new ConfigSlurper().parse(config)
// I know it works without this line but I prefer
// to keep one flat map (for other reasons)
flat_config_map = flat_config_map.flatten()
def engine = new GStringTemplateEngine()
// Question: is there a way to define this template to output "Hello foo"
// even from a flat map (e.g. with key "person.name") ?
def template = 'Hello ${person.name}'
println engine.createTemplate(template).make(flat_config_map)
The closest solution I found is through a quoted identifier but it needs to encapsulate in another object ? Something like: ${config."person.name"}
?
Thanks for your help.
Update (after marked as duplicate):
I forgot an important point. I use "ConfigSlurper" and "GStringTemplate" from Java as external libraries. I use those libs because they do the job but I'm really not familiar with Groovy. Moreover I don't want to mix language in my component.
Basically, I want to do:
Parameters in a file (ConfigSlurper) => flat Map (Java) => Template in a file (GStringTemplateEngine)
The flat Map step is important for me because in java world, it's easier to deal with only one level of properties (indexed with keys like "level1.level2") than with multi-level maps.
Thanks for your comments but I don't think it's duplicate because I'm rather looking for a syntax to solve it in the template file.