Skip to content

Commit

Permalink
Update Kotlin Examples and add a mapping to Java 14 record example
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphr committed May 29, 2020
1 parent 4abb0e9 commit f2139a6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ package org.mapstruct.example.kotlin.dto

import java.time.LocalDate

data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?) {

// Necessary for MapStruct
constructor() : this(null, null, null, null)

}
data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ package org.mapstruct.example.kotlin.model

import java.time.LocalDate

data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?) {

// Necessary for MapStruct
constructor() : this(null, null, null, null)

}
data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ package org.mapstruct.example.kotlin.dto

import java.time.LocalDate

data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?) {

// Necessary for MapStruct
constructor() : this(null, null, null, null)

}
data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ package org.mapstruct.example.kotlin.model

import java.time.LocalDate

data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?) {

// Necessary for MapStruct
constructor() : this(null, null, null, null)

}
data class Person(var firstName: String?, var lastName: String?, var phoneNumber: String?, var birthdate: LocalDate?)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.mapstruct.example;

import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
Expand All @@ -20,4 +21,7 @@ public interface CustomerMapper {
@Mapping(target = "mail", source = "email")
CustomerEntity fromRecord(CustomerDto record);

@InheritInverseConfiguration
CustomerDto toRecord(CustomerEntity entity);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,17 @@ public void mapRecords() {
assertThat( customer.getName() ).isEqualTo( "Kermit" );
assertThat( customer.getMail() ).isEqualTo( "[email protected]" );
}

@Test
public void mapToRecords() {
CustomerEntity entity = new CustomerEntity();
entity.setName( "Fozzie" );
entity.setMail( "[email protected]" );

CustomerDto customer = CustomerMapper.INSTANCE.toRecord( entity );

assertThat( customer ).isNotNull();
assertThat( customer.name() ).isEqualTo( "Fozzie" );
assertThat( customer.email() ).isEqualTo( "[email protected]" );
}
}

0 comments on commit f2139a6

Please sign in to comment.