Skip to content
Geoffrey Wiseman edited this page May 14, 2014 · 1 revision

In the simplest case, a property in Moo doesn't need a source expression. However, once you leave the simplest cases behind, source expressions are one of the most common configuration elements you might want to employ.

You can use them to identify slightly name changes, location shifts or even employ External Objects in Translation.

Optional

If the property on the source and target object has the same name, no translation expression is required:

public class Source {
  private String name;
}

public class Destination {
  @Property // no translation expresion required
  private String name;
}

Name Changes

The simplest kind of translation expression is simply a rename -- you're telling Moo that the name of the property in the source object is something a little different:

public class AmericanHome {
  private String tvModel;
}

public class BritishHome {
  @Property(source="tvModel")
  private String tellyModel;
}

Location Changes

More complicated translation expressions might be used to map a simple structure to a complex one or vice versa.

public class Policy {
  private List<Owner> owners;
}

public class PolicySummary {
  @Property(source="mvel:owners[1].name")
  private primaryOwnerName;
}

Complex translation expressions can be written in MVEL if you use the MVEL extension (see Extensions).

Collection Items

You can use expressions on each item in a collection as well. For instance, you might have a Role object in your domain that you want to collapse down to a simple String:

@CollectionProperty(itemSource="name")
Set<String> roles;