Created
October 9, 2013 11:44
-
-
Save ivanarrizabalaga/6899973 to your computer and use it in GitHub Desktop.
Groovy: Dynamic access to nested properties via GString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map data=[ | |
one:[ | |
two:"2222", | |
three:"333" | |
] | |
] | |
String nestedExpression="one.two" | |
String output=nestedExpression.tokenize('.').inject(data) {v, k -> v."$k"} | |
println output // "2222" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment