Skip to content

Commit 2e9197c

Browse files
BAEL-7823: Using Mapstruct with Lombok (#16731)
* BAEL-7823: Using Mapstruct with Lombok * BAEL-7823: Using Mapstruct with Lombok * BAEL-7823: Review Comments
1 parent 01abf65 commit 2e9197c

File tree

8 files changed

+105
-3
lines changed

8 files changed

+105
-3
lines changed

mapstruct-2/pom.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
<artifactId>mapstruct</artifactId>
2020
<version>${org.mapstruct.version}</version>
2121
</dependency>
22+
<dependency>
23+
<groupId>org.projectlombok</groupId>
24+
<artifactId>lombok</artifactId>
25+
<version>${lombok.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.projectlombok</groupId>
29+
<artifactId>lombok-mapstruct-binding</artifactId>
30+
<version>${lombok.mapstruct.binding.version}</version>
31+
</dependency>
2232
</dependencies>
2333
<build>
2434
<finalName>mapstruct-2</finalName>
@@ -33,14 +43,24 @@
3343
<artifactId>mapstruct-processor</artifactId>
3444
<version>${org.mapstruct.version}</version>
3545
</path>
46+
<path>
47+
<groupId>org.projectlombok</groupId>
48+
<artifactId>lombok</artifactId>
49+
<version>${lombok.version}</version>
50+
</path>
51+
<path>
52+
<groupId>org.projectlombok</groupId>
53+
<artifactId>lombok-mapstruct-binding</artifactId>
54+
<version>${lombok.mapstruct.binding.version}</version>
55+
</path>
3656
</annotationProcessorPaths>
3757
</configuration>
3858
</plugin>
3959
</plugins>
4060
</build>
4161

4262
<properties>
43-
<org.mapstruct.version>1.6.0.Beta1</org.mapstruct.version>
63+
<org.mapstruct.version>1.6.0.Beta2</org.mapstruct.version>
4464
<lombok.mapstruct.binding.version>0.2.0</lombok.mapstruct.binding.version>
4565
</properties>
4666

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.dto;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class SimpleSource {
7+
8+
private String name;
9+
private String description;
10+
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.entity;
2+
3+
import lombok.Builder;
4+
import lombok.Getter;
5+
6+
@Builder
7+
@Getter
8+
public class LombokDestination {
9+
10+
private String name;
11+
private String description;
12+
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.entity;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class SimpleDestination {
7+
8+
private String name;
9+
private String description;
10+
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.mapper;
2+
3+
import org.mapstruct.Mapper;
4+
5+
import com.baeldung.dto.SimpleSource;
6+
import com.baeldung.entity.LombokDestination;
7+
import com.baeldung.entity.SimpleDestination;
8+
9+
@Mapper
10+
public interface LombokMapper {
11+
12+
SimpleDestination sourceToDestination(SimpleSource source);
13+
14+
LombokDestination sourceToLombokDestination(SimpleSource source);
15+
16+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.baeldung.mapper;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
import org.mapstruct.factory.Mappers;
6+
7+
import com.baeldung.dto.SimpleSource;
8+
import com.baeldung.entity.LombokDestination;
9+
import com.baeldung.entity.SimpleDestination;
10+
11+
public class LombokMapperUnitTest {
12+
13+
private final LombokMapper lombokMapper = Mappers.getMapper(LombokMapper.class);
14+
15+
@Test
16+
void whenDestinationIsMapped_thenIsSuccessful() {
17+
SimpleSource simpleSource = new SimpleSource();
18+
simpleSource.setName("file");
19+
simpleSource.setDescription("A text file.");
20+
21+
SimpleDestination simpleDestination = lombokMapper.sourceToDestination(simpleSource);
22+
Assertions.assertNotNull(simpleDestination);
23+
Assertions.assertEquals(simpleSource.getName(), simpleDestination.getName());
24+
Assertions.assertEquals(simpleSource.getDescription(), simpleDestination.getDescription());
25+
26+
LombokDestination lombokDestination = lombokMapper.sourceToLombokDestination(simpleSource);
27+
Assertions.assertNotNull(lombokDestination);
28+
Assertions.assertEquals(simpleSource.getName(), lombokDestination.getName());
29+
Assertions.assertEquals(simpleSource.getDescription(), lombokDestination.getDescription());
30+
}
31+
}

mapstruct/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
</build>
7474

7575
<properties>
76-
<org.mapstruct.version>1.6.0.Beta1</org.mapstruct.version>
76+
<org.mapstruct.version>1.6.0.Beta2</org.mapstruct.version>
7777
<springframework.version>4.3.4.RELEASE</springframework.version>
7878
<lombok.mapstruct.binding.version>0.2.0</lombok.mapstruct.binding.version>
7979
</properties>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@
11061106
<gitflow-incremental-builder.version>4.5.3</gitflow-incremental-builder.version>
11071107
<maven-jxr-plugin.version>3.3.0</maven-jxr-plugin.version>
11081108
<maven-pmd-plugin.version>3.21.0</maven-pmd-plugin.version>
1109-
<lombok.version>1.18.30</lombok.version>
1109+
<lombok.version>1.18.32</lombok.version>
11101110
<h2.version>2.2.224</h2.version>
11111111
<guava.version>33.0.0-jre</guava.version>
11121112
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>

0 commit comments

Comments
 (0)