#2133 @BeanMapping#resultType should not be applied to forged methods (#2134)

* #2133 reproducer

* #2133 solution
This commit is contained in:
Sjaak Derksen 2020-07-04 18:20:09 +02:00 committed by GitHub
parent 082704cc55
commit 81a88bdb6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 1 deletions

View File

@ -472,7 +472,10 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
}
private Type getReturnTypeToConstructFromSelectionParameters(SelectionParameters selectionParams) {
if ( selectionParams != null && selectionParams.getResultType() != null ) {
// resultType only applies to method that actually has @BeanMapping annotation, never to forged methods
if ( !( method instanceof ForgedMethod )
&& selectionParams != null
&& selectionParams.getResultType() != null ) {
return ctx.getTypeFactory().getType( selectionParams.getResultType() );
}
return null;

View File

@ -0,0 +1,75 @@
/*
* 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._2133;
import org.mapstruct.BeanMapping;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface Issue2133Mapper {
Issue2133Mapper INSTANCE = Mappers.getMapper( Issue2133Mapper.class );
@BeanMapping(resultType = Target.class)
AbstractTarget map(Source source);
class Source {
private EmbeddedDto embedded;
public EmbeddedDto getEmbedded() {
return embedded;
}
public void setEmbedded(EmbeddedDto embedded) {
this.embedded = embedded;
}
}
class Target extends AbstractTarget {
}
abstract class AbstractTarget {
private EmbeddedEntity embedded;
public EmbeddedEntity getEmbedded() {
return embedded;
}
public void setEmbedded(EmbeddedEntity embedded) {
this.embedded = embedded;
}
}
class EmbeddedDto {
private String s1;
public String getS1() {
return s1;
}
public void setS1(String s1) {
this.s1 = s1;
}
}
class EmbeddedEntity {
private String s1;
public String getS1() {
return s1;
}
public void setS1(String s1) {
this.s1 = s1;
}
}
}

View File

@ -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._2133;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
@IssueKey("2133")
@WithClasses( Issue2133Mapper.class )
@RunWith(AnnotationProcessorTestRunner.class)
public class Issue2133Test {
@Test
public void shouldCompile() {
}
}