-
Notifications
You must be signed in to change notification settings - Fork 8
Source Expressions
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.
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;
}
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;
}
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).
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;
- Five Minute Introduction
- Getting Moo
- Translating Object Properties
- Translating Collection Properties
- Translating Map Properties
- Source Expressions
- Access Modes
- Translating to Value Types
- Extensions
- External Objects in Translation
- Ignoring Properties
- Updating Collections
- Translation Target Factories
- Nested Updates
- Optional and Required Properties
- Order of Property Translation
- Constructors
- Lookup on Update
- Caching
Releases
Background