The central focal point of Orika is the MapperFactory, of which DefaultMapperFactory is the provided implementation. DefaultMapperFactory is constructed using a flent-style builder API, like so:
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
There are various methods available on the Builder which can be used to fine-tune the default behavior of Orika, and we will cover some of most interesting ones below:
Provide your own implementation of ConstructorResolverStrategy to take over this behavior, or just extend the default ma.glasnost.orika.constructor.SimpleConstructorResolverStrategy:
constructorResolverStrategy(ConstructorResolverStrategy constructorResolverStrategy);
Provide your own implementation of CompilerStrategy to take over this behavior, or just extend the default ma.glasnost.orika.impl.generator.JavassistCompilerStrategy
.
You can also use an alternative provided with Orika, ma.glasnost.orika.impl.generator.EclipseJdtCompilerStrategy
which is helpful for step-debugging generated mapper code; more information about this alternative is described in the troubleshooting and debugging page.
compilerStrategy(CompilerStrategy compilerStrategy);
Provide your own implementation of PropertyResolverStrategy to take over this behavior, or just extend the default ma.glasnost.orika.property.IntrospectorPropertyResolver
.
propertyResolverStrategy(PropertyResolverStrategy propertyResolverStrategy);
Provide your own implementation of ClassMapBuilderFactory to take over this behavior, or just extend the default ma.glasnost.orika.metadata.ClassMapBuilder.Factory
.
You can also use an alternative provided with Orika, ma.glasnost.orika.metadata.ScoringClassMapBuilder.Factory
which uses a word-scoring algorithm to determine a best-fit matching of the fields for a pair of types; it even attempts to auto-resolve matches down to the nested properties and multi-occurrence elements.
classMapBuilderFactory(ClassMapBuilderFactory classMapBuilderFactory);
You can configure whether or not Orika will perform auto-mapping at runtime for types that were not registered; this behavior is enabled by default, but it can be disabled for cases where you want to be absolutely explicit about all classes that are mapped.
useAutoMapping(boolean useAutoMapping);
You can configure whether or not Orika will map null values from the source to destination. This behavior is enabled by default, but it can be disabled for cases where you want to leave the destination properties untouched if the source property contains a null value.
mapNulls(boolean mapNulls);