-
Notifications
You must be signed in to change notification settings - Fork 8
Optional and Required Properties
In some cases, you might prefer that Moo not require a source for every property visible in the destination. If this is generally true of how you use Moo, you can use the [Moo Configuration] to set the default value, but if you want to make a small number of properties optional, you can do that as well.
You might find this useful when translating multiple members of a class hierarchy. For instance, if you were going to have a single class that summarizes a policy owner and a contingent policy owner, and you track the email address for the owner but not the contingent owner, you might:
@Access(AccessMode.FIELD)
public class OwnerSummary {
}
public class Owner {
private String name;
private String phoneNumber;
@Property(optionality=OPTIONAL)
private String emailAddress;
}
public class PrimaryOwner extends Owner {
private String emailAddress;
}
public class ContingentOwner extends Owner {
}
This allows you to translate the PrimaryOwner to an OwnerSummary that includes an email address, and translate the Contingent Owner to an OwnerSummary with no email address.
Judicious use of static imports makes the optionality
attribute a little less ugly.
- 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