Skip to content

Commit f2139a6

Browse files
committed
Update Kotlin Examples and add a mapping to Java 14 record example
1 parent 4abb0e9 commit f2139a6

6 files changed

Lines changed: 21 additions & 24 deletions

File tree

mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/dto/PersonDto.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@ package org.mapstruct.example.kotlin.dto
22

33
import java.time.LocalDate
44

5-
data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?) {
6-
7-
// Necessary for MapStruct
8-
constructor() : this(null, null, null, null)
9-
10-
}
5+
data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?)

mapstruct-kotlin-gradle/src/main/kotlin/org/mapstruct/example/kotlin/model/Person.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@ package org.mapstruct.example.kotlin.model
22

33
import java.time.LocalDate
44

5-
data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?) {
6-
7-
// Necessary for MapStruct
8-
constructor() : this(null, null, null, null)
9-
10-
}
5+
data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?)

mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/dto/PersonDto.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@ package org.mapstruct.example.kotlin.dto
22

33
import java.time.LocalDate
44

5-
data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?) {
6-
7-
// Necessary for MapStruct
8-
constructor() : this(null, null, null, null)
9-
10-
}
5+
data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?)

mapstruct-kotlin/src/main/kotlin/org/mapstruct/example/kotlin/model/Person.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@ package org.mapstruct.example.kotlin.model
22

33
import java.time.LocalDate
44

5-
data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?) {
6-
7-
// Necessary for MapStruct
8-
constructor() : this(null, null, null, null)
9-
10-
}
5+
data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?)

mapstruct-record/src/main/java/org/mapstruct/example/CustomerMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.mapstruct.example;
77

8+
import org.mapstruct.InheritInverseConfiguration;
89
import org.mapstruct.Mapper;
910
import org.mapstruct.Mapping;
1011
import org.mapstruct.factory.Mappers;
@@ -20,4 +21,7 @@ public interface CustomerMapper {
2021
@Mapping(target = "mail", source = "email")
2122
CustomerEntity fromRecord(CustomerDto record);
2223

24+
@InheritInverseConfiguration
25+
CustomerDto toRecord(CustomerEntity entity);
26+
2327
}

mapstruct-record/src/test/java/org/mapstruct/example/CustomerMapperTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,17 @@ public void mapRecords() {
2222
assertThat( customer.getName() ).isEqualTo( "Kermit" );
2323
assertThat( customer.getMail() ).isEqualTo( "kermit@test.com" );
2424
}
25+
26+
@Test
27+
public void mapToRecords() {
28+
CustomerEntity entity = new CustomerEntity();
29+
entity.setName( "Fozzie" );
30+
entity.setMail( "fozzie@test.com" );
31+
32+
CustomerDto customer = CustomerMapper.INSTANCE.toRecord( entity );
33+
34+
assertThat( customer ).isNotNull();
35+
assertThat( customer.name() ).isEqualTo( "Fozzie" );
36+
assertThat( customer.email() ).isEqualTo( "fozzie@test.com" );
37+
}
2538
}

0 commit comments

Comments
 (0)