Skip to content

Commit f8d1090

Browse files
committed
Add example with Java 14 records
1 parent 2f35157 commit f8d1090

7 files changed

Lines changed: 217 additions & 0 deletions

File tree

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ matrix:
1212
- jdk: openjdk11
1313
- jdk: openjdk12
1414
- jdk: openjdk13
15+
- jdk: openjdk14-ea
16+
- jdk: openjdk15-ea
1517
- jdk: openjdk-ea
1618
allow_failures:
19+
- jdk: openjdk15-ea
1720
- jdk: openjdk-ea
1821

1922
script: mvn clean verify -B -V -U

mapstruct-record/pom.xml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
5+
and/or other contributors as indicated by the @authors tag. See the
6+
copyright.txt file in the distribution for a full listing of all
7+
contributors.
8+
9+
Licensed under the Apache License, Version 2.0 (the "License");
10+
you may not use this file except in compliance with the License.
11+
You may obtain a copy of the License at
12+
13+
http://www.apache.org/licenses/LICENSE-2.0
14+
15+
Unless required by applicable law or agreed to in writing, software
16+
distributed under the License is distributed on an "AS IS" BASIS,
17+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
See the License for the specific language governing permissions and
19+
limitations under the License.
20+
21+
-->
22+
<project xmlns="http://maven.apache.org/POM/4.0.0"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
25+
<modelVersion>4.0.0</modelVersion>
26+
27+
<groupId>org.mapstruct.examples.record</groupId>
28+
<artifactId>mapstruct-examples-record</artifactId>
29+
<version>1.0-SNAPSHOT</version>
30+
31+
<packaging>jar</packaging>
32+
33+
<properties>
34+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
35+
<maven.compiler.source>14</maven.compiler.source>
36+
<maven.compiler.target>14</maven.compiler.target>
37+
<maven.compiler.release>14</maven.compiler.release>
38+
<org.mapstruct.version>1.4.0-SNAPSHOT</org.mapstruct.version>
39+
</properties>
40+
41+
42+
<dependencies>
43+
44+
<dependency>
45+
<groupId>org.mapstruct</groupId>
46+
<artifactId>mapstruct</artifactId>
47+
<version>${org.mapstruct.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.mapstruct</groupId>
51+
<artifactId>mapstruct-processor</artifactId>
52+
<version>${org.mapstruct.version}</version>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>junit</groupId>
57+
<artifactId>junit</artifactId>
58+
<scope>test</scope>
59+
<version>4.12</version>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.assertj</groupId>
63+
<artifactId>assertj-core</artifactId>
64+
<version>3.14.0</version>
65+
<scope>test</scope>
66+
</dependency>
67+
</dependencies>
68+
69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-compiler-plugin</artifactId>
74+
<version>3.8.0</version>
75+
<configuration>
76+
<compilerArgs>--enable-preview</compilerArgs>
77+
<annotationProcessorPaths>
78+
<path>
79+
<groupId>org.mapstruct</groupId>
80+
<artifactId>mapstruct-processor</artifactId>
81+
<version>${org.mapstruct.version}</version>
82+
</path>
83+
</annotationProcessorPaths>
84+
</configuration>
85+
</plugin>
86+
<plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-surefire-plugin</artifactId>
89+
<version>3.0.0-M4</version>
90+
<configuration>
91+
<forkCount>1</forkCount>
92+
<argLine>--enable-preview</argLine>
93+
</configuration>
94+
</plugin>
95+
</plugins>
96+
</build>
97+
98+
<repositories>
99+
<repository>
100+
<id>sonatype-oss-snapshot</id>
101+
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
102+
<releases>
103+
<enabled>false</enabled>
104+
</releases>
105+
<snapshots>
106+
<enabled>true</enabled>
107+
</snapshots>
108+
</repository>
109+
</repositories>
110+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.example;
7+
8+
/**
9+
* @author Filip Hrisafov
10+
*/
11+
public record CustomerDto(String name, String email) {
12+
13+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.example;
7+
8+
/**
9+
* @author Filip Hrisafov
10+
*/
11+
public class CustomerEntity {
12+
13+
private String name;
14+
private String mail;
15+
16+
public String getName() {
17+
return name;
18+
}
19+
20+
public void setName(String name) {
21+
this.name = name;
22+
}
23+
24+
public String getMail() {
25+
return mail;
26+
}
27+
28+
public void setMail(String mail) {
29+
this.mail = mail;
30+
}
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.example;
7+
8+
import org.mapstruct.Mapper;
9+
import org.mapstruct.Mapping;
10+
import org.mapstruct.factory.Mappers;
11+
12+
/**
13+
* @author Filip Hrisafov
14+
*/
15+
@Mapper
16+
public interface CustomerMapper {
17+
18+
CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class );
19+
20+
@Mapping(target = "mail", source = "email")
21+
CustomerEntity fromRecord(CustomerDto record);
22+
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.example;
7+
8+
import org.junit.Test;
9+
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
12+
/**
13+
* @author Filip Hrisafov
14+
*/
15+
public class CustomerMapperTest {
16+
17+
@Test
18+
public void mapRecords() {
19+
CustomerEntity customer = CustomerMapper.INSTANCE.fromRecord( new CustomerDto( "Kermit", "kermit@test.com" ) );
20+
21+
assertThat( customer ).isNotNull();
22+
assertThat( customer.getName() ).isEqualTo( "Kermit" );
23+
assertThat( customer.getMail() ).isEqualTo( "kermit@test.com" );
24+
}
25+
}

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,16 @@
4747
<module>mapstruct-mapper-repo</module>
4848
<module>mapstruct-quarkus</module>
4949
</modules>
50+
51+
<profiles>
52+
<profile>
53+
<id>java14+</id>
54+
<activation>
55+
<jdk>[14,)</jdk>
56+
</activation>
57+
<modules>
58+
<module>mapstruct-record</module>
59+
</modules>
60+
</profile>
61+
</profiles>
5062
</project>

0 commit comments

Comments
 (0)