Groovy web console

subscribe to the feed Subscribe
to this
site

Map convert Strings to Booleans

Published 2 months ago by Jose Sa with tags string2boolean
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def config = [aa:"true", bb:"false", cc:true, dd:false]

println "[ begin ]"
config.each { println it.key + " : " + it.value.getClass() }

// convert string to boolean
def stringKeys = []
config.findAll { it.value == "true" || it.value == "false"}.each{stringKeys << it?.key}
stringKeys.each { config."$it" = config."$it".toBoolean() }

println "[ end ]"
config.each { println it.key + " : " + it.value.getClass() }