
- MapStruct - Home
- MapStruct - Overview
- MapStruct - Environment Setup
- MapStruct - Mapping
- MapStruct - Basic Mapping
- MapStruct - Custom Mapping
- MapStruct - Mapping Multiple
- MapStruct - Mapping Nested Bean
- MapStruct - Mapping Direct Field
- MapStruct - Builder
- MapStruct - Data Type Conversions
- MapStruct - Implicit Type Conversion
- MapStruct - Using numberFormat
- MapStruct - Using dateFormat
- MapStruct - Using expression
- MapStruct - Using constant
- MapStruct - Using defaultValue
- MapStruct - Using defaultExpression
- MapStruct - Mapping Collections
- MapStruct - Mapping List
- MapStruct - Mapping Map
- Mapstruct - Miscellaneous
- MapStruct - Mapping Streams
- MapStruct - Mapping Enum
- MapStruct - Throwing Exceptions
- MapStruct - Customizing Mapper
- MapStruct - Useful Resources
- MapStruct - Quick Guide
- MapStruct - Useful Resources
- MapStruct - Discussion

MapStruct Tutorial
What is Mapstruct?
The MapStruct is an annotation based code generator/mapper which greatly simplifies the mapping implementations of Java Beans. It follows convention over configuration, uses plain method invocations. MapStruct operations are very fast, type-safe and easy to understand.
Why Mapping is required?
In multilayered applications, data objects are used to fetch data from database and UI interacts with Models. Now data fetched into data models is required to map to Model or java beans to be passed to UI. When attributes of a class becomes very high or project size grows, data objects synchronization with UI objects becomes unmanagable. Here Mapstruct works to smoothen the data movement from database to UI.
This MapStruct tutorial is based on the latest Mapstruct 1.6.3 version.
How MapStruct Works?
MapStruct automates the process of creating a mapper to map data objects with model objects using annotations. It creates a mapper implementation at compile time which helps developer to figure out error during development and make is easy to understand. For example −
StudentMapper.java
@Mapper class StudentMapper { StudentMapper INSTANCE = Mappers.getMapper( StudentMapper.class ); StudentEntity modelToEntity(Student student); }
Now StudentMapper.INSTANCE can be used to get mapped objects easily.
StudentEntity studentEntity = StudentMapper.INSTANCE.modelToEntity(student);
Who Should Learn Mapstruct?
Mapstruct is a nice mapping library to automate data movement from database entity to user interface models in simple and easy ways. It is great for those who want to build java based applications and automate data mapping between objects. Students and educators can also benefit from its flexibility and ease of use.
Prerequisites to Learn Mapstruct
To learn Mapstruct, you should have a basic understanding of Java Programming Language.