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
Expand Up @@ -146,13 +146,30 @@ public static ForgedMethod forSubclassMapping(String name, Type sourceType, Type
basedOn,
history,
mappingReferences == null ? MappingReferences.empty() : mappingReferences,
forgedNameBased
forgedNameBased,
MappingMethodOptions.getSubclassForgedMethodInheritedOptions( basedOn.getOptions() )
);
}

private ForgedMethod(String name, Type sourceType, Type returnType, List<Parameter> additionalParameters,
Method basedOn, ForgedMethodHistory history, MappingReferences mappingReferences,
boolean forgedNameBased) {
this(
name,
sourceType,
returnType,
additionalParameters,
basedOn,
history,
mappingReferences,
forgedNameBased,
MappingMethodOptions.getForgedMethodInheritedOptions( basedOn.getOptions() )
);
}

private ForgedMethod(String name, Type sourceType, Type returnType, List<Parameter> additionalParameters,
Method basedOn, ForgedMethodHistory history, MappingReferences mappingReferences,
boolean forgedNameBased, MappingMethodOptions options) {

// establish name
String sourceParamSafeName;
Expand Down Expand Up @@ -185,7 +202,7 @@ private ForgedMethod(String name, Type sourceType, Type returnType, List<Paramet
this.mappingReferences = mappingReferences;
this.forgedNameBased = forgedNameBased;

this.options = MappingMethodOptions.getForgedMethodInheritedOptions( basedOn.getOptions() );
this.options = options;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ public static BeanMappingOptions forForgedMethods(BeanMappingOptions beanMapping
return options;
}

public static BeanMappingOptions forSubclassForgedMethods(BeanMappingOptions beanMapping) {

return new BeanMappingOptions(
beanMapping.selectionParameters != null ?
SelectionParameters.withoutResultType( beanMapping.selectionParameters ) : null,
beanMapping.ignoreUnmappedSourceProperties,
beanMapping.beanMapping,
beanMapping
);
}

public static BeanMappingOptions empty(DelegatingOptions delegatingOptions) {
return new BeanMappingOptions( null, Collections.emptyList(), null, delegatingOptions );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,17 @@ public static MappingMethodOptions getForgedMethodInheritedOptions(MappingMethod
null );
}

public static MappingMethodOptions getSubclassForgedMethodInheritedOptions(MappingMethodOptions options) {
return new MappingMethodOptions(
options.mapper,
options.mappings,
options.iterableMapping,
options.mapMapping,
BeanMappingOptions.forSubclassForgedMethods( options.beanMapping ),
options.enumMappingOptions,
options.valueMappings,
Collections.emptySet(),
null );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._3609;

import org.mapstruct.BeanMapping;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.SubclassMapping;

@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR)
public abstract class Issue3609Mapper {

@SubclassMapping(source = CarDto.class, target = Car.class)
@BeanMapping(ignoreUnmappedSourceProperties = "id")
public abstract Vehicle toVehicle(VehicleDto vehicle);

//CHECKSTYLE:OFF
public static class Vehicle {
public int price;
}

public static class Car extends Vehicle {
public int seats;

public Car(int price, int seats) {
this.price = price;
this.seats = seats;
}
}

public static class VehicleDto {
public int id;
public int price;
}

public static class CarDto extends VehicleDto {
public int seats;
}
//CHECKSTYLE:ON
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._3609;

import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;

/**
* @author Roman Obolonskyii
*/
@IssueKey("3609")
@WithClasses(Issue3609Mapper.class)
public class Issue3609Test {

@ProcessorTest
void shouldCompileWithoutErrors() {

}
}