I want to use either a value of expected property or a specified default. How to achieve this in groovy?
Let\'s look at the example:
def printName(ob
You can use hasProperty. Example:
if (object.hasProperty('name') && object.name) { println object.name } else { println object }
If you're using a variable for the property name, you can use this:
String propName = 'name' if (object.hasProperty(propName) && object."$propName") { ... }