Groovy web console

subscribe to the feed Subscribe
to this
site
Dot-notation dynamic properties (via #groovywebconsole)
tweet this snippet Tweet
this
script

Dot-notation dynamic properties

Published 1 year ago by Phil DeJarnett with tags dynamic property
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def input = [foo: [bar: 'baz']]

def fieldName = 'foo.bar'

def fieldValue = fieldName.split(/\./).inject(input){ parent, property -> parent?."$property" }

assert fieldValue == 'baz'