Class DozerBeanMapperBuilder


  • public final class DozerBeanMapperBuilder
    extends Object
    Builds an instance of Mapper. Provides fluent interface to configure every aspect of the mapper. Everything which is not explicitly specified will receive its default value. Please refer to class methods for possible configuration options.
    • Method Detail

      • create

        public static DozerBeanMapperBuilder create()
        Creates new builder. All the configuration has its default values.
        Returns:
        new instance of the builder.
      • buildDefault

        public static Mapper buildDefault()
        Creates an instance of Mapper, with all the configuration set to its default values.

        The only special handling is for mapping file. If there is a file with name dozerBeanMapping.xml available on classpath, this file will be used by created mapper. Otherwise the mapper is implicit.

        Returns:
        new instance of Mapper with default configuration and optionally initiated mapping file.
      • withMappingFiles

        public DozerBeanMapperBuilder withMappingFiles​(String... mappingFiles)
        Adds mappingFiles to the list of URLs to be used as mapping configuration. It is possible to load files from file system via file: prefix. If no prefix is given, loaded from classpath.

        Multiple calls of this method will result in all the files being added to the list of mappings in the order methods were called.

        If not called, no files will be added to the mapping configuration, and mapper will use implicit mode.

        Parameters:
        mappingFiles - URLs to mapping files to be added.
        Returns:
        modified builder to be further configured.
      • withMappingFiles

        public DozerBeanMapperBuilder withMappingFiles​(List<String> mappingFiles)
        Adds mappingFiles to the list of URLs to be used as mapping configuration. It is possible to load files from file system via file: prefix. If no prefix is given, loaded from classpath.

        Multiple calls of this method will result in all the files being added to the list of mappings in the order methods were called.

        If not called, no files will be added to the mapping configuration, and mapper will use implicit mode.

        Parameters:
        mappingFiles - URLs to mapping files to be added.
        Returns:
        modified builder to be further configured.
      • withClassLoader

        public DozerBeanMapperBuilder withClassLoader​(DozerClassLoader classLoader)
        Sets DozerClassLoader to be used whenever Dozer needs to load a class or resource.

        By default, if Dozer is executed in OSGi environment, OSGiClassLoader will be used (i.e. delegate loading to Dozer bundle classloader). If Dozer is executed in non-OSGi environment, classloader of DozerBeanMapperBuilder will be used (wrapped into DefaultClassLoader).

        Parameters:
        classLoader - custom classloader to be used by Dozer.
        Returns:
        modified builder to be further configured.
      • withClassLoader

        public DozerBeanMapperBuilder withClassLoader​(ClassLoader classLoader)
        Sets classloader to be used whenever Dozer needs to load a class or resource.

        By default, if Dozer is executed in OSGi environment, OSGiClassLoader will be used (i.e. delegate loading to Dozer bundle classloader). If Dozer is executed in non-OSGi environment, classloader of DozerBeanMapperBuilder will be used (wrapped into DefaultClassLoader).

        Parameters:
        classLoader - custom classloader to be used by Dozer. Will be wrapped into DefaultClassLoader.
        Returns:
        modified builder to be further configured.
      • withCustomConverter

        public DozerBeanMapperBuilder withCustomConverter​(CustomConverter customConverter)
        Registers a CustomConverter for the mapper. Multiple calls of this method will register converters in the order of calling.

        By default, no custom converters are used by generated mapper.

        Parameters:
        customConverter - converter to be registered.
        Returns:
        modified builder to be further configured.
      • withCustomConverters

        public DozerBeanMapperBuilder withCustomConverters​(CustomConverter... customConverters)
        Registers a CustomConverter for the mapper. Multiple calls of this method will register converters in the order of calling.

        By default, no custom converters are used by generated mapper.

        Parameters:
        customConverters - converters to be registered.
        Returns:
        modified builder to be further configured.
      • withCustomConverters

        public DozerBeanMapperBuilder withCustomConverters​(List<CustomConverter> customConverters)
        Registers a CustomConverter for the mapper. Multiple calls of this method will register converters in the order of calling.

        By default, no custom converters are used by generated mapper.

        Parameters:
        customConverters - converters to be registered.
        Returns:
        modified builder to be further configured.
      • withXmlMapping

        public DozerBeanMapperBuilder withXmlMapping​(Supplier<InputStream> xmlMappingSupplier)
        Registers a supplier of InputStream which is expected to contain data of XML mapping file. At the moment of create() method call, suppliers will be called in the order they were registered, the data of each stream will be read and processed, stream will be immediately closed.

        Please note, XML mappings are processed before fluent builder mappings. Although it is not recommended to mix the approaches.

        By default, no XML mappings are registered.

        Parameters:
        xmlMappingSupplier - supplier of a Dozer mapping XML InputStream.
        Returns:
        modified builder to be further configured.
      • withMappingBuilder

        public DozerBeanMapperBuilder withMappingBuilder​(BeanMappingBuilder mappingBuilder)
        Registers a BeanMappingBuilder for the mapper. Multiple calls of this method will register builders in the order of calling.

        Builders are executed at the moment of create() method call.

        Please note, XML mappings are processed before Java builder mappings. Although it is not recommended to mix the approaches.

        By default, no API builders are registered.

        Parameters:
        mappingBuilder - mapping builder to be registered for the mapper.
        Returns:
        modified builder to be further configured.
      • withMappingBuilders

        public DozerBeanMapperBuilder withMappingBuilders​(BeanMappingBuilder... mappingBuilders)
        Registers a BeanMappingBuilder for the mapper. Multiple calls of this method will register builders in the order of calling.

        Builders are executed at the moment of create() method call.

        Please note, XML mappings are processed before Java builder mappings. Although it is not recommended to mix the approaches.

        By default, no API builders are registered.

        Parameters:
        mappingBuilders - mapping builder to be registered for the mapper.
        Returns:
        modified builder to be further configured.
      • withMappingBuilders

        public DozerBeanMapperBuilder withMappingBuilders​(List<BeanMappingBuilder> mappingBuilders)
        Registers a BeanMappingBuilder for the mapper. Multiple calls of this method will register builders in the order of calling.

        Builders are executed at the moment of create() method call.

        Please note, XML mappings are processed before Java builder mappings. Although it is not recommended to mix the approaches.

        By default, no API builders are registered.

        Parameters:
        mappingBuilders - mapping builder to be registered for the mapper.
        Returns:
        modified builder to be further configured.
      • withBeanMappingsBuilders

        public DozerBeanMapperBuilder withBeanMappingsBuilders​(BeanMappingsBuilder beanMappingsBuilder)
        Registers a BeanMappingsBuilder for the mapper. Multiple calls of this method will register builders in the order of calling.

        Builders are executed at the moment of create() method call.

        Current implementations include; BeanMappingXMLBuilder

        By default, no API builders are registered.

        Parameters:
        beanMappingsBuilder - mapping builder to be registered for the mapper.
        Returns:
        modified builder to be further configured.
      • withBeanMappingsBuilders

        public DozerBeanMapperBuilder withBeanMappingsBuilders​(BeanMappingsBuilder... beanMappingsBuilder)
        Registers a BeanMappingsBuilder for the mapper. Multiple calls of this method will register builders in the order of calling.

        Builders are executed at the moment of create() method call.

        Current implementations include; BeanMappingXMLBuilder

        By default, no API builders are registered.

        Parameters:
        beanMappingsBuilder - mapping builder to be registered for the mapper.
        Returns:
        modified builder to be further configured.
      • withBeanMappingsBuilders

        public DozerBeanMapperBuilder withBeanMappingsBuilders​(List<BeanMappingsBuilder> beanMappingsBuilder)
        Registers a BeanMappingsBuilder for the mapper. Multiple calls of this method will register builders in the order of calling.

        Builders are executed at the moment of create() method call.

        Current implementations include; BeanMappingXMLBuilder

        By default, no API builders are registered.

        Parameters:
        beanMappingsBuilder - mapping builder to be registered for the mapper.
        Returns:
        modified builder to be further configured.
      • withEventListener

        public DozerBeanMapperBuilder withEventListener​(EventListener eventListener)
        Registers a EventListener for the mapper. Multiple calls of this method will register listeners in the order of calling.

        By default, no listeners are registered.

        Parameters:
        eventListener - listener to be registered for the mapper.
        Returns:
        modified builder to be further configured.
      • withEventListeners

        public DozerBeanMapperBuilder withEventListeners​(EventListener... eventListeners)
        Registers a EventListener for the mapper. Multiple calls of this method will register listeners in the order of calling.

        By default, no listeners are registered.

        Parameters:
        eventListeners - listeners to be registered for the mapper.
        Returns:
        modified builder to be further configured.
      • withEventListeners

        public DozerBeanMapperBuilder withEventListeners​(List<EventListener> eventListeners)
        Registers a EventListener for the mapper. Multiple calls of this method will register listeners in the order of calling.

        By default, no listeners are registered.

        Parameters:
        eventListeners - listeners to be registered for the mapper.
        Returns:
        modified builder to be further configured.
      • withCustomFieldMapper

        public DozerBeanMapperBuilder withCustomFieldMapper​(CustomFieldMapper customFieldMapper)
        Registers a CustomFieldMapper for the mapper. Mapper has only one custom field mapper, and thus consecutive calls of this method will override previously specified value.

        By default, no custom field mapper is registered.

        Parameters:
        customFieldMapper - custom field mapper to be registered for the mapper.
        Returns:
        modified builder to be further configured.
      • withCustomConverterWithId

        public DozerBeanMapperBuilder withCustomConverterWithId​(String converterId,
                                                                CustomConverter converter)
        Registers a CustomConverter which can be referenced in mapping by provided ID. Consecutive calls of this method with the same ID will override previously provided value.

        Converter instances provided this way are considered stateful and will not be initialized for each mapping.

        By default, no converters with IDs are registered.

        Parameters:
        converterId - unique ID of the converter, used as reference in mappings.
        converter - converter to be used for provided ID.
        Returns:
        modified builder to be further configured.
      • withCustomConvertersWithIds

        public DozerBeanMapperBuilder withCustomConvertersWithIds​(Map<String,​CustomConverter> customConvertersWithId)
        Registers a CustomConverter which can be referenced in mapping by provided ID. Consecutive calls of this method with the same ID will override previously provided value.

        Converter instances provided this way are considered stateful and will not be initialized for each mapping.

        By default, no converters with IDs are registered.

        Parameters:
        customConvertersWithId - converters to be used by mapper.
        Returns:
        modified builder to be further configured.
      • withBeanFactory

        public DozerBeanMapperBuilder withBeanFactory​(String factoryName,
                                                      BeanFactory beanFactory)
        Registers a BeanFactory for the mapper. Consecutive calls of this method with the same factory name will override previously provided value.

        By default, no custom bean factories are registered.

        Parameters:
        factoryName - unique name of the factory.
        beanFactory - factory to be used by mapper.
        Returns:
        modified builder to be further configured.
      • withBeanFactorys

        public DozerBeanMapperBuilder withBeanFactorys​(Map<String,​BeanFactory> beanFactories)
        Registers a BeanFactory for the mapper. Consecutive calls of this method with the same factory name will override previously provided value.

        By default, no custom bean factories are registered.

        Parameters:
        beanFactories - factory's to be used by mapper.
        Returns:
        modified builder to be further configured.
      • withELEngine

        public DozerBeanMapperBuilder withELEngine​(ELEngine elEngine)
        Registers a ELEngine for the mapper. Which can be used to resolve expressions within the defined mappings.

        By default, NoopELEngine is registered, unless ExpressionFactoryImpl is detected on classpath, then DefaultELEngine

        Parameters:
        elEngine - elEngine to use
        Returns:
        modified builder to be further configured.
      • withElementReader

        public DozerBeanMapperBuilder withElementReader​(ElementReader elementReader)
        Registers a ElementReader for the mapper. Which can be used to resolve expressions within the defined XML mappings.

        By default, SimpleElementReader are registered, unless ExpressionFactoryImpl is detected on classpath, then ExpressionElementReader

        Parameters:
        elementReader - elementReader to use
        Returns:
        modified builder to be further configured.
      • withCacheManager

        public DozerBeanMapperBuilder withCacheManager​(CacheManager cacheManager)
        Registers a CacheManager for the mapper. Which can be used to control the caching behaviour

        By default, DefaultCacheManager are registered

        Parameters:
        cacheManager - cacheManager to use
        Returns:
        modified builder to be further configured.
      • build

        public Mapper build()
        Creates an instance of Mapper. Mapper is configured according to the current builder state.

        Subsequent calls of this method will return new instances.

        Returns:
        new instance of Mapper.