This repository contains examples showing how to use MapStruct, a Java annotation processor for the generation of type-safe bean mapping classes.
Currently, the following examples exist:
- mapstruct-on-ant: Shows how to use MapStruct in Ant-based projects; to build this example, run
ant buildon the command line - mapstruct-on-gradle: Shows how to use MapStruct in Gradle-based projects; to build the example project, run
./gradlew clean buildon the command line - mapstruct-lombok: Shows how to use MapStruct together with Lombok (with both a Maven
pom.xmland a Gradlebuild.gradle); to build the example project, run eithermvn clean installor./gradlew clean buildon the command line - mapstruct-iterable-non-iterable: Shows how by means of a mapper util class conversions can be made from an iterable- to its non-iterable element
- mapstruct-mapping-from-map: Shows how by means of a mapper util class and qualifiers extracting value can be carried out on Maps. Watch mapstruct/mapstruct#1075 for native support.
- mapstruct-rounding: Shows how by means of a mapper util class and qualifiers roundings can be carried out on Numbers
- mapstruct-examples-updatemethods-1: Shows how to update an existing target object
- mapstruct-examples-field-mapping: Shows how MapStruct can be used with "struct" like objects with public fields
- mapstruct-nested-bean-mappings: Shows how to map object graphs via a main root method
- mapstruct-mapping-with-cycles: Shows how to map object graphs that can contain cycles
- mapstruct-on-android-with-autovalue-builders: Shows how MapStruct works with builders for immutable objects in an Android sample project.
- mapstruct-spi-accessor-naming: Example on how to use the Service Provider Interface (SPI) for a custom accessor naming strategy.
- mapstruct-protobuf3: Example on how to use protobuf3 with MapStruct
- mapstruct-kotlin: Example on how to use MapStruct with Kotlin using KAPT (Kotlin Annotation Processing Tool)
- mapstruct-kotlin-gradle: Example on how to use MapStruct with Kotlin and Gradle Kotlin DSL using KAPT
- mapstruct-jpa-parent-child: Example on how to use @Context in relation to parent / child relations in JPA
- mapstruct-suppress-unmapped: Shows how mapping to target properties can be ignored without warning by default in a mixed scenario. However bean property mappings that have the same name will still be applied.
- mapstruct-lookup-entity-with-composed-key: Shows how an object with composite key can be read from the database in a mapping method.
- mapstruct-clone: Shows how an object can be deeply cloned by defining all mapping methods.
- mapstruct-metadata-annotations: Demonstrates how to read annotations and use them as mapping instruction.
The integration tests are also a valuable resource for inspecting how MapStruct works. Here is the entire collection integration test resources and here is an example for AutoValue as one of those integrations tests.
The examples in this project are licensed under the Apache License, Version 2.0.