-
-
Notifications
You must be signed in to change notification settings - Fork 963
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3717 Fix ClassCastException when getting thrown types for a record a…
…ccessor
- Loading branch information
Showing
6 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
.../test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/Address.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.nested; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public record Address(String street, String city) { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
.../resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.nested; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public record CareProvider(String externalId, Address address) { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...sources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProviderDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.nested; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public record CareProviderDto(String id, String street, String city) { | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...rces/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProviderMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.nested; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.ReportingPolicy; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) | ||
public interface CareProviderMapper { | ||
|
||
CareProviderMapper INSTANCE = Mappers.getMapper( CareProviderMapper.class ); | ||
|
||
@Mapping(target = "id", source = "externalId") | ||
@Mapping(target = "street", source = "address.street") | ||
@Mapping(target = "city", source = "address.city") | ||
CareProviderDto map(CareProvider source); | ||
} |
26 changes: 26 additions & 0 deletions
26
...urces/recordsTest/src/test/java/org/mapstruct/itest/records/nested/NestedRecordsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.nested; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
public class NestedRecordsTest { | ||
|
||
@Test | ||
public void shouldMapRecord() { | ||
CareProvider source = new CareProvider( "kermit", new Address( "Sesame Street", "New York" ) ); | ||
CareProviderDto target = CareProviderMapper.INSTANCE.map( source ); | ||
|
||
assertThat( target ).isNotNull(); | ||
assertThat( target.id() ).isEqualTo( "kermit" ); | ||
assertThat( target.street() ).isEqualTo( "Sesame Street" ); | ||
assertThat( target.city() ).isEqualTo( "New York" ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters