mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3135 BeanMapping#mappingControl should be inherited by forged methods
This commit is contained in:
parent
53baf96126
commit
9794543946
@ -54,6 +54,17 @@ public class BeanMappingOptions extends DelegatingOptions {
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BeanMappingOptions forForgedMethods(BeanMappingOptions beanMapping) {
|
||||||
|
BeanMappingOptions options = new BeanMappingOptions(
|
||||||
|
beanMapping.selectionParameters != null ?
|
||||||
|
SelectionParameters.withoutResultType( beanMapping.selectionParameters ) : null,
|
||||||
|
Collections.emptyList(),
|
||||||
|
beanMapping.beanMapping,
|
||||||
|
beanMapping
|
||||||
|
);
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
public static BeanMappingOptions empty(DelegatingOptions delegatingOptions) {
|
public static BeanMappingOptions empty(DelegatingOptions delegatingOptions) {
|
||||||
return new BeanMappingOptions( null, Collections.emptyList(), null, delegatingOptions );
|
return new BeanMappingOptions( null, Collections.emptyList(), null, delegatingOptions );
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ public class MappingMethodOptions {
|
|||||||
options.mappings,
|
options.mappings,
|
||||||
options.iterableMapping,
|
options.iterableMapping,
|
||||||
options.mapMapping,
|
options.mapMapping,
|
||||||
BeanMappingOptions.empty( options.beanMapping.next() ),
|
BeanMappingOptions.forForgedMethods( options.beanMapping ),
|
||||||
options.enumMappingOptions,
|
options.enumMappingOptions,
|
||||||
options.valueMappings,
|
options.valueMappings,
|
||||||
Collections.emptySet(),
|
Collections.emptySet(),
|
||||||
|
@ -39,6 +39,10 @@ public class SelectionParameters {
|
|||||||
* @return the selection parameters based on the given ones
|
* @return the selection parameters based on the given ones
|
||||||
*/
|
*/
|
||||||
public static SelectionParameters forInheritance(SelectionParameters selectionParameters) {
|
public static SelectionParameters forInheritance(SelectionParameters selectionParameters) {
|
||||||
|
return withoutResultType( selectionParameters );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SelectionParameters withoutResultType(SelectionParameters selectionParameters) {
|
||||||
return new SelectionParameters(
|
return new SelectionParameters(
|
||||||
selectionParameters.qualifiers,
|
selectionParameters.qualifiers,
|
||||||
selectionParameters.qualifyingNames,
|
selectionParameters.qualifyingNames,
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* 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.mappingcontrol;
|
||||||
|
|
||||||
|
import org.mapstruct.BeanMapping;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.control.DeepClone;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CloningBeanMappingMapper {
|
||||||
|
|
||||||
|
CloningBeanMappingMapper INSTANCE = Mappers.getMapper( CloningBeanMappingMapper.class );
|
||||||
|
|
||||||
|
@BeanMapping(mappingControl = DeepClone.class)
|
||||||
|
FridgeDTO clone(FridgeDTO in);
|
||||||
|
|
||||||
|
}
|
@ -69,6 +69,21 @@ public class MappingControlTest {
|
|||||||
assertThat( out.getShelve().getCoolBeer().getBeerCount() ).isEqualTo( "5" );
|
assertThat( out.getShelve().getCoolBeer().getBeerCount() ).isEqualTo( "5" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ProcessorTest
|
||||||
|
@IssueKey("3135")
|
||||||
|
@WithClasses(CloningBeanMappingMapper.class)
|
||||||
|
public void testDeepCloningViaBeanMapping() {
|
||||||
|
|
||||||
|
FridgeDTO in = createFridgeDTO();
|
||||||
|
FridgeDTO out = CloningBeanMappingMapper.INSTANCE.clone( in );
|
||||||
|
|
||||||
|
assertThat( out ).isNotNull();
|
||||||
|
assertThat( out.getShelve() ).isNotNull();
|
||||||
|
assertThat( out.getShelve() ).isNotSameAs( in.getShelve() );
|
||||||
|
assertThat( out.getShelve().getCoolBeer() ).isNotSameAs( in.getShelve().getCoolBeer() );
|
||||||
|
assertThat( out.getShelve().getCoolBeer().getBeerCount() ).isEqualTo( "5" );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the deep cloning annotation with lists
|
* Test the deep cloning annotation with lists
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user