Groovy: Dynamic nested properties

144 views Asked by At

I have a chain of properties that I may need to access. For example:

  • device.room
  • device.room.usageArea
  • ...
  • device.room.usageArea.floor.building.account

I know that I can get a property with a dynamic string in the way device."${property}", but it doesn't work for a deep nesting.

How can I dynamically access to the account property, with a string chain given (such as properties = device."room.usageArea.floor.building.account")

Edit

I tried a way that is working, but I'm not proud of it:

Eval.me 'device', device, "device.${properties}"

where properties is a string with dot-separated properties

0

There are 0 answers