[SOLVED] Groovy dynamic object properties from string get and set

If you need to evaluate some properties of an object from strings like:

person is

class Person {
  Name name
class Name {
  String first
  String second


	def evalProperty(object, String property) {
	  Eval.x(object, 'x.' + property)

And the setter 🙂

	void setProperty(Object object, String propertyPath, Object value) {
		def pathElements = propertyPath.tokenize('.')
		Object parent = evalProperty(object, pathElements[0..-2].join('.'))
		parent[pathElements[-1]] = value


evalProperty(person, 'name.first')
setProperty(person,'name.first','New Name')