mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3609 Pass bean mapping ignored unmapped source properties to subclass forged methods
Co-authored-by: thunderhook <8238759+thunderhook@users.noreply.github.com>
This commit is contained in:
parent
66f4288842
commit
df49ce5ff9
@ -146,13 +146,30 @@ public class ForgedMethod implements Method {
|
||||
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;
|
||||
@ -185,7 +202,7 @@ public class ForgedMethod implements Method {
|
||||
this.mappingReferences = mappingReferences;
|
||||
this.forgedNameBased = forgedNameBased;
|
||||
|
||||
this.options = MappingMethodOptions.getForgedMethodInheritedOptions( basedOn.getOptions() );
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,6 +66,17 @@ public class BeanMappingOptions extends DelegatingOptions {
|
||||
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 );
|
||||
}
|
||||
|
@ -398,4 +398,17 @@ public class MappingMethodOptions {
|
||||
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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
}
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user