1. Overview

In this tutorial, we’ll take a look at how to map collections of objects using MapStruct.

Since this article assumes already a basic understanding of MapStruct, beginners should check out our quick guide to MapStruct first.

2. Mapping Collections

In general, mapping collections with MapStruct works in the same way as for simple types.

Basically, we have to create a simple interface or abstract class and declare the mapping methods. Based on our declarations, MapStruct will generate the mapping code automatically. Typically, the generated code will loop over the source collection, convert each element to the target type, and include each of them in the target collection.

Let’s take a look at a simple example.

#java

Mapping Collections with MapStruct
21.80 GEEK