All Projects → mapstruct → Mapstruct

mapstruct / Mapstruct

Licence: other
An annotation processor for generating type-safe bean mappers

Programming Languages

java
68154 projects - #9 most used programming language
FreeMarker
481 projects

Projects that are alternatives of or similar to Mapstruct

mapstruct-idea
An IntelliJ IDEA plugin for working with MapStruct
Stars: ✭ 80 (-98.3%)
Mutual labels:  mapping, mapstruct
smartstruct
Dart Code Generator for generating mapper classes
Stars: ✭ 20 (-99.58%)
Mutual labels:  annotation-processor, mapstruct
Mapnik
Mapnik is an open source toolkit for developing mapping applications
Stars: ✭ 3,067 (-34.88%)
Mutual labels:  mapping
Parceler
📦 Android Parcelables made easy through code generation.
Stars: ✭ 3,589 (-23.8%)
Mutual labels:  annotation-processor
Sparse To Dense
ICRA 2018 "Sparse-to-Dense: Depth Prediction from Sparse Depth Samples and a Single Image" (Torch Implementation)
Stars: ✭ 329 (-93.01%)
Mutual labels:  mapping
Awesome Gee
A curated list of Google Earth Engine resources
Stars: ✭ 292 (-93.8%)
Mutual labels:  mapping
Dynamic robot localization
Point cloud registration pipeline for robot localization and 3D perception
Stars: ✭ 339 (-92.8%)
Mutual labels:  mapping
Mapper
OpenOrienteering Mapper is a software for creating maps for the orienteering sport.
Stars: ✭ 258 (-94.52%)
Mutual labels:  mapping
Android Api Securekeys
Store data in a simple and secure way
Stars: ✭ 372 (-92.1%)
Mutual labels:  annotation-processor
Pojobuilder
A Java Code Generator for Pojo Builders
Stars: ✭ 326 (-93.08%)
Mutual labels:  annotation-processor
Arrow
🏹 Parse JSON with style
Stars: ✭ 355 (-92.46%)
Mutual labels:  mapping
Jackdaw
Java Annotation Processor which allows to simplify development
Stars: ✭ 306 (-93.5%)
Mutual labels:  annotation-processor
Leaflet.markercluster
Marker Clustering plugin for Leaflet
Stars: ✭ 3,305 (-29.83%)
Mutual labels:  mapping
Preferenceroom
🚚 Android processing library for managing SharedPreferences persistence efficiently and structurally.
Stars: ✭ 341 (-92.76%)
Mutual labels:  annotation-processor
Blade
Android library for boilerplate destruction
Stars: ✭ 278 (-94.1%)
Mutual labels:  annotation-processor
Aerial mapper
Real-time Dense Point Cloud, Digital Surface Map (DSM) and (Ortho-)Mosaic Generation for UAVs
Stars: ✭ 360 (-92.36%)
Mutual labels:  mapping
Immutables
Annotation processor to create immutable objects and builders. Feels like Guava's immutable collections but for regular value objects. JSON, Jackson, Gson, JAX-RS integrations included
Stars: ✭ 3,031 (-35.65%)
Mutual labels:  annotation-processor
Vscode Todo Highlight
a vscode extension to highlighting todos, fixmes, and any annotations...
Stars: ✭ 305 (-93.52%)
Mutual labels:  annotation-processor
Sc Lego Loam
LiDAR SLAM: Scan Context + LeGO-LOAM
Stars: ✭ 332 (-92.95%)
Mutual labels:  mapping
Handyjson
A handy swift json-object serialization/deserialization library
Stars: ✭ 3,913 (-16.92%)
Mutual labels:  mapping

MapStruct - Java bean mappings, the easy way!

Latest Stable Version Latest Version License

Build Status Coverage Status Gitter Code Quality: Java Total Alerts

What is MapStruct?

MapStruct is a Java annotation processor for the generation of type-safe and performant mappers for Java bean classes. It saves you from writing mapping code by hand, which is a tedious and error-prone task. The generator comes with sensible defaults and many built-in type conversions, but it steps out of your way when it comes to configuring or implementing special behavior.

Compared to mapping frameworks working at runtime, MapStruct offers the following advantages:

  • Fast execution by using plain method invocations instead of reflection
  • Compile-time type safety. Only objects and attributes mapping to each other can be mapped, so there's no accidental mapping of an order entity into a customer DTO, etc.
  • Self-contained code—no runtime dependencies
  • Clear error reports at build time if:
    • mappings are incomplete (not all target properties are mapped)
    • mappings are incorrect (cannot find a proper mapping method or type conversion)
  • Easily debuggable mapping code (or editable by hand—e.g. in case of a bug in the generator)

To create a mapping between two types, declare a mapper class like this:

@Mapper
public interface CarMapper {

    CarMapper INSTANCE = Mappers.getMapper( CarMapper.class );

    @Mapping(target = "seatCount", source = "numberOfSeats")
    CarDto carToCarDto(Car car);
}

At compile time MapStruct will generate an implementation of this interface. The generated implementation uses plain Java method invocations for mapping between source and target objects, i.e. no reflection is involved. By default, properties are mapped if they have the same name in source and target, but you can control this and many other aspects using @Mapping and a handful of other annotations.

Requirements

MapStruct requires Java 1.8 or later.

Using MapStruct

MapStruct works in command line builds (plain javac, via Maven, Gradle, Ant, etc.) and IDEs.

For Eclipse, a dedicated plug-in is in development (see https://github.com/mapstruct/mapstruct-eclipse). It goes beyond what's possible with an annotation processor, providing content assist for annotation attributes, quick fixes and more.

For IntelliJ the plug-in is available within the IntelliJ marketplace (see https://plugins.jetbrains.com/plugin/10036-mapstruct-support).

Maven

For Maven-based projects, add the following to your POM file in order to use MapStruct (the dependencies are available at Maven Central):

...
<properties>
    <org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
</properties>
...
<dependencies>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct</artifactId>
        <version>${org.mapstruct.version}</version>
    </dependency>
</dependencies>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${org.mapstruct.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>
...

Gradle

For Gradle, you need something along the following lines:

plugins {
    ...
    id "com.diffplug.eclipse.apt" version "3.26.0" // Only for Eclipse
}

dependencies {
    ...
    compile 'org.mapstruct:mapstruct:1.4.2.Final'

    annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
    testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' // if you are using mapstruct in test code
}
...

If you don't work with a dependency management tool, you can obtain a distribution bundle from SourceForge.

Documentation and getting help

To learn more about MapStruct, refer to the project homepage. The reference documentation covers all provided functionality in detail. If you need help, come and join the mapstruct-users group.

Building from Source

MapStruct uses Maven for its build. Java 8 is required for building MapStruct from source. To build the complete project, run

mvn clean install

from the root of the project directory. To skip the distribution module, run

mvn clean install -DskipDistribution=true

Importing into IDE

MapStruct uses the gem annotation processor to generate mapping gems for it's own annotations. Therefore for seamless integration within an IDE annotation processing needs to be enabled.

IntelliJ

Make sure that you have at least IntelliJ 2018.2.x (needed since support for annotationProcessors from the maven-compiler-plugin is from that version). Enable annotation processing in IntelliJ (Build, Execution, Deployment -> Compiler -> Annotation Processors)

Eclipse

Make sure that you have the m2e_apt plugin installed.

Links

Licensing

MapStruct is licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].