Ok, so with the map you dropped in the question, you can do:
import groovy.yaml.YamlBuilder
Map mymap = [1: "a, b, c ,d", 2: "y, d, x"]
def config = new YamlBuilder()
config {
"Content" mymap
}
println config.toString()
Which prints
---
Content:
"1": "a, b, c ,d"
"2": "y, d, x"
As you can see, your input map just has String values, not lists...
If you meant to give your input map as:
Map mymap = [1: ["a", "b", "c", "d"], 2: ["y", "d", "x"]]
Then the above code prints out
---
Content:
"1":
- "a"
- "b"
- "c"
- "d"
"2":
- "y"
- "d"
- "x"
Which is what you say you want...
If the original map was correct and you're being sent comma separated Strings to represent lists, then you'll need to munge them yourself into lists
Map mymap = [1: "a, b, c ,d", 2: "y, d, x"]
mymap = mymap.collectEntries { k, v ->
[k, v.split(",")*.trim()]
}
def config = new YamlBuilder()
config {
"Content" mymap
}
println config.toString()
Which again gives you
---
Content:
"1":
- "a"
- "b"
- "c"
- "d"
"2":
- "y"
- "d"
- "x"