-
Notifications
You must be signed in to change notification settings - Fork 9
Translation Target Factories
Instances of TranslationTargetFactory
can be used to construct a 'target' instance before the properties are translated into it. This can be useful when translating from one class hierarchy to another, or when the destination class is an interface and you want a choice about the implementation.
Moo provides several of these instances which are used by default in specific cases.
When translating object properties (annotated with @Property
or implicitly defined), the DefaultObjectTargetFactory
is responsible for constructing the target object, invoking any NoArgument constructor of the destination type. This is also the class that constructs target objects for collection items, map keys and map targets.
When translating collection properties (annotated with @CollectionProperty
or implicitly defined), the DefaultCollectionTargetFactory
is responsible for constructing the target collection. It does this by constructing a preferred collection implementation for each core collection interface:
-
SortedSet
=>TreeSet
-
Set
=>HashSet
-
List
=>ArrayList
-
Collection
=>ArrayList
When translating map properties (annotated with @MapProperty
or implicitly defined), the DefaultMapTargetFactory
is responsible for constructing the target map. It does this by constructing a preferred collection implementation for the two core Map
interfaces:
-
SortedMap
=>TreeMap
-
Map
=>HashMap
When these defaults aren't sufficient, you can take control over the construction of the target type by overriding the default translation target factory:
@Property(factory=MyOwnClassHierarchyFactory.class)
@CollectionProperty(factory=IPreferLinkedList.class)
@MapProperty(factory=MyCustomMapFactory.class)
Implementations of TranslationTargetFactory
are pretty simple, and you can look at the core implementations for inspiration. I could also make these core implementations customizable with configuration but that doesn't seem necessary yet.
- 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