Skip to content

Instantly share code, notes, and snippets.

@dnoseda
Created April 17, 2012 14:36
Show Gist options
  • Save dnoseda/2406374 to your computer and use it in GitHub Desktop.
Save dnoseda/2406374 to your computer and use it in GitHub Desktop.
uncamelize key of map in groovy
Map toUncamelizedKeyMap(Map map){
(map+[:]).each{k,v->
map[k.replaceAll(/([A-Z])/,'_$1').toLowerCase()] = v
}
return map
}
Map toCamelizedKeyMap(def map){
(map+[:]).each{k,v->
def camelized = k.split("_").collect({"${it[0].toUpperCase()}${it[1..-1]}"}).join()
map[camelized[0].toLowerCase()+camelized[1..-1]] = v
}
return map
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment