Top Related Projects
An annotation processor for generating type-safe bean mappers
Intelligent object mapping
Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another.
Quick Overview
Orika is a Java-based, open-source mapping framework that simplifies the process of converting between different object models. It provides a straightforward way to map complex object structures, supporting deep mapping, custom converters, and bidirectional mapping. Orika is designed to be fast, flexible, and easy to use.
Pros
- High performance with minimal overhead
- Supports complex object structures and deep mapping
- Easy to configure and use with a fluent API
- Extensible through custom mappers and converters
Cons
- Limited documentation and examples for advanced use cases
- Not actively maintained (last release in 2018)
- May have compatibility issues with newer Java versions
- Lacks some features found in newer mapping libraries
Code Examples
- Basic mapping between two classes:
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(Source.class, Destination.class).byDefault().register();
MapperFacade mapper = mapperFactory.getMapperFacade();
Destination dest = mapper.map(source, Destination.class);
- Custom field mapping:
mapperFactory.classMap(Person.class, PersonDTO.class)
.field("firstName", "givenName")
.field("lastName", "surname")
.byDefault()
.register();
- Using a custom converter:
mapperFactory.getConverterFactory().registerConverter(new DateToStringConverter());
mapperFactory.classMap(Event.class, EventDTO.class)
.fieldMap("date", "dateString").converter("dateToString")
.byDefault()
.register();
Getting Started
To use Orika in your project, add the following dependency to your Maven pom.xml
:
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.5.4</version>
</dependency>
Create a MapperFactory
and configure your mappings:
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(Source.class, Destination.class).byDefault().register();
MapperFacade mapper = mapperFactory.getMapperFacade();
Destination dest = mapper.map(source, Destination.class);
For more complex mappings, use the fluent API to configure field mappings, converters, and other options as needed.
Competitor Comparisons
An annotation processor for generating type-safe bean mappers
Pros of MapStruct
- Compile-time code generation, resulting in faster execution and earlier error detection
- Type-safe mapping with minimal runtime overhead
- Extensive IDE support and integration
Cons of MapStruct
- Steeper learning curve due to annotation-based configuration
- Less flexibility for complex mappings compared to Orika's runtime approach
Code Comparison
MapStruct:
@Mapper
public interface CarMapper {
@Mapping(source = "numberOfSeats", target = "seatCount")
CarDto carToCarDto(Car car);
}
Orika:
mapperFactory.classMap(Car.class, CarDto.class)
.field("numberOfSeats", "seatCount")
.byDefault()
.register();
Key Differences
- MapStruct uses compile-time code generation, while Orika performs runtime mapping
- MapStruct relies on annotations for configuration, Orika uses a fluent API
- MapStruct offers better performance, while Orika provides more flexibility for complex mappings
Both libraries are popular choices for Java object mapping, with MapStruct generally preferred for simpler, performance-critical mappings, and Orika favored for more complex, dynamic mapping scenarios.
Intelligent object mapping
Pros of ModelMapper
- More flexible and customizable mapping configurations
- Better support for complex object graphs and nested mappings
- Easier to use with minimal configuration for simple use cases
Cons of ModelMapper
- Generally slower performance compared to Orika
- Steeper learning curve for advanced mapping scenarios
- Less type-safe mapping operations
Code Comparison
ModelMapper:
ModelMapper modelMapper = new ModelMapper();
DestinationType dest = modelMapper.map(source, DestinationType.class);
Orika:
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
MapperFacade mapper = mapperFactory.getMapperFacade();
DestinationType dest = mapper.map(source, DestinationType.class);
Key Differences
- ModelMapper uses reflection-based mapping, while Orika generates bytecode for better performance
- Orika requires more explicit configuration for complex mappings, but offers better type safety
- ModelMapper provides more out-of-the-box conventions and intelligent mapping strategies
Use Cases
- ModelMapper: Ideal for projects with complex object structures and frequent mapping changes
- Orika: Better suited for high-performance applications with stable mapping requirements
Both libraries offer powerful object mapping capabilities, but the choice between them depends on specific project needs, performance requirements, and developer preferences.
Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another.
Pros of Dozer
- More extensive documentation and community support
- Supports XML-based mapping configuration
- Better integration with Spring Framework
Cons of Dozer
- Generally slower performance compared to Orika
- More verbose configuration, especially for complex mappings
- Heavier memory footprint
Code Comparison
Dozer mapping configuration:
DozerBeanMapper mapper = new DozerBeanMapper();
mapper.addMapping(new BeanMappingBuilder() {
@Override
protected void configure() {
mapping(Source.class, Destination.class)
.fields("sourceField", "destField");
}
});
Orika mapping configuration:
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(Source.class, Destination.class)
.field("sourceField", "destField")
.register();
Both Dozer and Orika are popular Java bean mapping frameworks, but they have distinct differences in performance, configuration, and features. Orika generally offers better performance and a more streamlined API, while Dozer provides more extensive documentation and better Spring integration. The choice between the two depends on specific project requirements and preferences.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Orika !
NEW We are pleased to announce the release of Orika 1.5.4 ! This version is available on Maven central repository
What?
Orika is a Java Bean mapping framework that recursively copies (among other capabilities) data from one object to another. It can be very useful when developing multi-layered applications.
Why?
Struggling with hand coded and reflection-based mappers? Orika can be used to simplify the process of mapping between one object layer and another.
Our ambition is to build a comprehensive, efficient and robust Java bean mapping solution. Orika focuses on automating as much as possible, while providing customization through configuration and extension where needed.
Orika enables the developer to :
- Map complex and deeply structured objects
- "Flatten" or "Expand" objects by mapping nested properties to top-level properties, and vice versa
- Create mappers on-the-fly, and apply customizations to control some or all of the mapping
- Create converters for complete control over the mapping of a specific set of objects anywhere in the object graph--by type, or even by specific property name
- Handle proxies or enhanced objects (like those of Hibernate, or the various mock frameworks)
- Apply bi-directional mapping with one configuration
- Map to instances of an appropriate concrete class for a target abstract class or interface
- Map POJO properties to Lists, Arrays, and Maps
How?
Orika uses byte code generation to create fast mappers with minimal overhead.
Want to give Orika a try? Check out our new User Guide
Acknowledgements
-
YourKit supports Orika with its full-featured Java Profiler. Take a look at YourKit's leading software products: YourKit Java Profiler.
-
JetBrains kindly provides Orika with a free open-source licence for their IntelliJ IDEA Ultimate edition.
Top Related Projects
An annotation processor for generating type-safe bean mappers
Intelligent object mapping
Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot