Skip to content

Instantly share code, notes, and snippets.

@forgo
Created September 28, 2018 18:39
Show Gist options
  • Select an option

  • Save forgo/310d614f49e183308d653f90ebff6d2f to your computer and use it in GitHub Desktop.

Select an option

Save forgo/310d614f49e183308d653f90ebff6d2f to your computer and use it in GitHub Desktop.
Debug Groovy Map Key Hierarchy
def mapStructure(Map map, int layer = 0) {
map.each { key, value ->
println "${('\t' * layer) + key}: ${layer.toString()}"
if(value.getClass() == LinkedHashMap.class) {
mapStructure((Map)value, layer+1)
}
}
}
// Example usage:
/*
Map map = [
input: [
method: "POST",
host: "hostname",
requestURL: "https://www.whatever.com"
],
content: "<xml>whatever</xml>",
id: [ source1: '123456' ]
]
mapStructure(map)
*/
// Example output:
/*
input:
method:
host:
requestURL:
content:
id:
source1:
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment