mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3717 Fix ClassCastException when getting thrown types for a record accessor
This commit is contained in:
parent
c74e62a94c
commit
a3b4139070
@ -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) {
|
||||
|
||||
}
|
@ -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) {
|
||||
|
||||
}
|
@ -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) {
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
@ -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" );
|
||||
}
|
||||
}
|
@ -491,7 +491,11 @@ public class TypeFactory {
|
||||
if (accessor.getAccessorType().isFieldAssignment()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return extractTypes( ( (ExecutableElement) accessor.getElement() ).getThrownTypes() );
|
||||
Element element = accessor.getElement();
|
||||
if ( element instanceof ExecutableElement ) {
|
||||
return extractTypes( ( (ExecutableElement) element ).getThrownTypes() );
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private List<Type> extractTypes(List<? extends TypeMirror> typeMirrors) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user