or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bean-factory.mdbuilder-configuration.mdcore-mapping.mdcustom-conversion.mdevent-system.mdindex.mdmetadata-access.mdprogrammatic-mapping.md
tile.json

tessl/maven-com-github-dozermapper--dozer-core

Java Bean to Java Bean mapper that recursively copies data from one object to another

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.github.dozermapper/dozer-core@6.5.x

To install, run

npx @tessl/cli install tessl/maven-com-github-dozermapper--dozer-core@6.5.0

index.mddocs/

Dozer Core

Dozer is a powerful Java Bean to Java Bean mapper that recursively copies data from one object to another. It provides automatic property mapping with extensive customization options for complex mapping scenarios, including deep object graphs, collections, and custom type conversions.

Package Information

  • Package Name: com.github.dozermapper:dozer-core
  • Package Type: Maven
  • Language: Java
  • Installation:
    <dependency>
      <groupId>com.github.dozermapper</groupId>
      <artifactId>dozer-core</artifactId>
      <version>6.5.2</version>
    </dependency>

Core Imports

import com.github.dozermapper.core.Mapper;
import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.DozerBeanMapper;
import com.github.dozermapper.core.MappingException;

Basic Usage

import com.github.dozermapper.core.Mapper;
import com.github.dozermapper.core.DozerBeanMapperBuilder;

// Create mapper instance (should be singleton)
Mapper mapper = DozerBeanMapperBuilder.buildDefault();

// Simple mapping - creates new destination instance
PersonDto dto = mapper.map(person, PersonDto.class);

// Map to existing instance
PersonDto existingDto = new PersonDto();
mapper.map(person, existingDto);

// Map with custom configuration
Mapper customMapper = DozerBeanMapperBuilder.create()
    .withMappingFiles("dozer-mappings.xml")
    .withCustomConverter(new DateToStringConverter())
    .build();

Architecture

Dozer core is built around several key components:

  • Mapper Interface: Main entry point providing mapping operations
  • Builder Pattern: Fluent configuration API via DozerBeanMapperBuilder
  • Custom Conversion System: Extensible converter framework for complex type transformations
  • Event System: Lifecycle hooks for mapping operations
  • Mapping Configuration: XML and programmatic mapping definitions
  • Caching System: Performance optimization through intelligent caching
  • Module System: Plugin architecture for extending functionality

Capabilities

Core Mapping Operations

Primary mapping functionality for copying data between Java objects with automatic property matching and type conversion.

public interface Mapper {
    <T> T map(Object source, Class<T> destinationClass) throws MappingException;
    void map(Object source, Object destination) throws MappingException;
    <T> T map(Object source, Class<T> destinationClass, String mapId) throws MappingException;
    void map(Object source, Object destination, String mapId) throws MappingException;
    MappingMetadata getMappingMetadata();
    MapperModelContext getMapperModelContext();
}

Core Mapping

Builder Configuration

Fluent API for creating and configuring mapper instances with custom settings, converters, and mapping files.

public final class DozerBeanMapperBuilder {
    public static DozerBeanMapperBuilder create();
    public static Mapper buildDefault();
    public DozerBeanMapperBuilder withMappingFiles(String... mappingFiles);
    public DozerBeanMapperBuilder withCustomConverter(CustomConverter customConverter);
    public DozerBeanMapperBuilder withEventListener(EventListener eventListener);
    public Mapper build();
}

Builder Configuration

Custom Conversion System

Extensible converter framework for handling complex type transformations and custom mapping logic.

public interface CustomConverter {
    Object convert(Object existingDestinationFieldValue, Object sourceFieldValue, 
                  Class<?> destinationClass, Class<?> sourceClass);
}

public abstract class DozerConverter<A, B> implements ConfigurableCustomConverter {
    public DozerConverter(Class<A> prototypeA, Class<B> prototypeB);
    public abstract B convertTo(A source, B destination);
    public abstract A convertFrom(B source, A destination);
}

Custom Conversion

Programmatic Mapping API

Fluent Java API for defining mappings programmatically without XML configuration files.

public abstract class BeanMappingBuilder {
    public abstract void configure();
    protected TypeMappingBuilder mapping(Class<?> typeA, Class<?> typeB, TypeMappingOption... options);
    protected FieldDefinition field(String name);
    protected TypeDefinition type(Class<?> type);
}

Programmatic Mapping

Event System

Lifecycle hooks for intercepting and customizing mapping operations at various stages.

public interface EventListener {
    void onMappingStarted(Event event);
    void onPreWritingDestinationValue(Event event);
    void onPostWritingDestinationValue(Event event);
    void onMappingFinished(Event event);
}

public interface Event {
    EventTypes getType();
    ClassMap getClassMap();
    FieldMap getFieldMap();
    Object getSourceObject();
    Object getDestinationObject();
    Object getDestinationValue();
}

Event System

Metadata and Introspection

Runtime access to mapping metadata and configuration for debugging and dynamic behavior.

public interface MappingMetadata {
    List<ClassMappingMetadata> getClassMappings();
    List<ClassMappingMetadata> getClassMappingsBySource(Class<?> sourceClass);
    List<ClassMappingMetadata> getClassMappingsByDestination(Class<?> destinationClass);
    ClassMappingMetadata getClassMapping(Class<?> sourceClass, Class<?> destinationClass);
}

Metadata Access

Bean Factory System

Custom object creation during mapping for advanced instantiation patterns and dependency injection integration.

public interface BeanFactory {
    Object createBean(Object source, Class<?> sourceClass, String targetBeanId, BeanContainer beanContainer);
}

Bean Factory System

Exception Handling

public class MappingException extends RuntimeException {
    public MappingException(String message);
    public MappingException(String message, Throwable cause);
    public MappingException(Throwable cause);
}

Dozer throws MappingException for all mapping-related errors including:

  • Type conversion failures
  • Configuration errors
  • Custom converter exceptions
  • Bean instantiation failures