-
Notifications
You must be signed in to change notification settings - Fork 8
Translating Object Properties
Object properties can be translated with explicit configuration or implicitly.
When a class is translated, Moo will search that class for properties using the default Access Mode (see Access Modes). Any properties found this way will be translated from the source, if they can be found.
You can configure the default access mode in the Moo Configuration
class, or you can change the access mode for a class using the @AccessMode
annotation. Alternately, you can configure properties of the object for explicit translation.
In addition to any implicitly-located properties, you might choose to explicitly configure the properties on a class. There are lots of reasons to do this and lots of ways to do this.
The most common would be to include the @Property
annotation on a property, but the @Ignore
or @Optionality
attributes would also qualify.
You can mark properties as being ignored for translation with the @Ignore
annotation if they're properties that might be picked up implicitly and you don't want them to be picked up (see Ignoring Properties).
If you don't want to ignore the property, you want it to be translated when it's available but get no complaints when it is not, then you might want to look at the @Optionality
annotation or the optionality attribute on the Property annotation (see Optional and Required Properties).
You might mark a field or method with the Property
annotation if you just want to pick up a property that might not otherwise be found:
@Access(AccessMode.METHOD)
public MyClass {
@Property
private OtherClass other;
}
Or you might need one of the many attributes on the @Property annotation.
In some cases, the source object for the property might not be as simple as the field or property with the same name as the destination. You might have a different name on the source, or you might need to translate only a single property of the source, or you might have a more complicated translation that requires the assistance of outside objects. The source attribute can help you with all of these cases.
(see Source Expressions)
Not every property needs a translation. Some can simply be copied. The translate attribute allows you to identify if the source object requires a translation before it can be used in the destination.
Some properties should be totally replaced with a new translation, others can be updated from the source object or from the translation. The update attribute allows you to control whether the object can be updated (update=true
) or should be replaced (update=false
).
As above, sometimes an attribute might be optional. You can use the optionality attribute or the optionality annotation to let Moo know.
(see Optional and Required Properties)
Moo will create the destination object for you when a translation is required, but sometimes the destination object that Moo would create isn't the one you would have picked. In that case, you might need a TranslationTargetFactory
to help out.
- 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