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,24 @@
/*
* 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;

import java.util.List;

/**
* @author Filip Hrisafov
*/
public class Car {

private List<WheelPosition> wheelPositions;

public List<WheelPosition> getWheelPositions() {
return wheelPositions;
}

public void setWheelPositions(List<WheelPosition> wheelPositions) {
this.wheelPositions = wheelPositions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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;

import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

/**
* @author Filip Hrisafov
*/
@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR)
public interface CarAndWheelMapper {

CarAndWheelMapper INSTANCE = Mappers.getMapper( CarAndWheelMapper.class );

default String stringFromWheelPosition(WheelPosition source) {
return source == null ? null : source.getPosition();
}

default WheelPosition wheelPositionFromString(String source) {
return source == null ? null : new WheelPosition(source);
}

CarDto carDtoFromCar(Car source);

Car carFromCarDto(CarDto source);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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;

import java.util.List;

/**
* @author Filip Hrisafov
*/
public record CarDto(List<String> wheelPositions) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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;

/**
* @author Filip Hrisafov
*/
public class WheelPosition {

private final String position;

public WheelPosition(String position) {
this.position = position;
}

public String getPosition() {
return position;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
package org.mapstruct.itest.records;

import java.util.Arrays;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
Expand Down Expand Up @@ -47,4 +49,16 @@ public void shouldMapIntoGenericRecord() {
assertThat( value ).isNotNull();
assertThat( value.value() ).isEqualTo( "Kermit" );
}

@Test
public void shouldMapIntoRecordWithList() {
Car car = new Car();
car.setWheelPositions( Arrays.asList( new WheelPosition( "left" ) ) );

CarDto carDto = CarAndWheelMapper.INSTANCE.carDtoFromCar(car);

assertThat( carDto ).isNotNull();
assertThat( carDto.wheelPositions() )
.containsExactly( "left" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,13 @@ private List<Accessor> getAdders() {
* @return an unmodifiable list of alternative target accessors.
*/
private List<Accessor> getAlternativeTargetAccessors() {
if ( alternativeTargetAccessors != null ) {
return alternativeTargetAccessors;
}

if ( isRecord() ) {
alternativeTargetAccessors = Collections.emptyList();
}

if ( alternativeTargetAccessors == null ) {

Expand Down