Expressions and Method invocations

When it's not enough of usual mapping rules you can use expressions to calculate some properties. Expressions are nothing else as Groovy closures. They are calculated during mapping and can access mapping context, a and b instances.

  a.mappingTime = { new Date() } // a.mappingTime is calculated each time when b is mapped to a
  a.fullName = { b.firstName + " " + b.lastName } // concatenating first and last names

  a.hasChildren = { b.details.kids != null && b.details.kids.size() > 0 } // checking whether b has kids
  a.hasChildren = { b.details.kids?.size() > 0 } // as the previous but using Groovy null-safe operator ?

You can also invokes a method on one of the sides.

  mappingFor a: Person, b: Employee

  b.firstName = a.fullName.split("\\s+")[0]
  b.lastName = a.fullName.split("\\s+")[1]

  b.dump = a.toString()

Notice that method invocations can be only data sources.