Another newbie issue. I have a situation where I have to assign a value to domain class property in groovy.
The code is
cf.”$it.key” = it.value
the property type for cf.”$it.key” can be Integer, Long or String – but it.value is always a String. I have seen that when cf.”$it.key” is Integer or Long, groovy converts it.value to ascii value( for example if it.value is “6”, cf.”$it.key” becomes 54, when it is “7”, it becomes 55 and so on). As of now, I have resolved the issue by introducing check methods as shown below. But was wondering if there is a better solution to the problem.
if (it.value.isInteger()){ cf."$it.key" = new Integer(it.value) } else if (it.value.isLong()){ cf."$it.key" = new Long(it.value) }
Thanks
Assuming you’re iterating through a map,you should be able to use bindData, i.e.
Make sure you read that section of the docs though, as there are security implications