Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {

}
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) {

}
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) {

}
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);
}
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" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,11 @@ public List<Type> getThrownTypes(Accessor accessor) {
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) {
Expand Down