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 @@ -1276,8 +1276,16 @@ else if ( mapping.getJavaExpression() != null ) {
.options( mapping )
.build();
handledTargets.add( targetPropertyName );
unprocessedSourceParameters.remove( sourceRef.getParameter() );
unprocessedSourceProperties.remove( sourceRef.getShallowestPropertyName() );
Parameter sourceParameter = sourceRef.getParameter();
unprocessedSourceParameters.remove( sourceParameter );
// If the source parameter was directly mapped
if ( sourceRef.getPropertyEntries().isEmpty() ) {
// Ignore all of its source properties completely
ignoreSourceProperties( sourceParameter );
}
else {
unprocessedSourceProperties.remove( sourceRef.getShallowestPropertyName() );
}
}
else {
errorOccured = true;
Expand Down Expand Up @@ -1452,23 +1460,25 @@ private void applyParameterNameBasedMapping() {
sourceParameters.remove();
unprocessedDefinedTargets.remove( targetProperty.getKey() );
unprocessedSourceProperties.remove( targetProperty.getKey() );

// The source parameter was directly mapped so ignore all of its source properties completely
if ( !sourceParameter.getType().isPrimitive() && !sourceParameter.getType().isArrayType() ) {
// We explicitly ignore source properties from primitives or array types
Map<String, ReadAccessor> readAccessors = sourceParameter.getType()
.getPropertyReadAccessors();
for ( String sourceProperty : readAccessors.keySet() ) {
unprocessedSourceProperties.remove( sourceProperty );
}
}

unprocessedConstructorProperties.remove( targetProperty.getKey() );
ignoreSourceProperties( sourceParameter );
}
}
}
}

private void ignoreSourceProperties(Parameter sourceParameter) {
// The source parameter was directly mapped so ignore all of its source properties completely
if ( !sourceParameter.getType().isPrimitive() && !sourceParameter.getType().isArrayType() ) {
// We explicitly ignore source properties from primitives or array types
Map<String, ReadAccessor> readAccessors = sourceParameter.getType()
.getPropertyReadAccessors();
for ( String sourceProperty : readAccessors.keySet() ) {
unprocessedSourceProperties.remove( sourceProperty );
}
}
}

private SourceReference getSourceRefByTargetName(Parameter sourceParameter, String targetPropertyName) {

SourceReference sourceRef = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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._2781;

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

/**
* @author Mengxing Yuan
*/
@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR)
public interface Issue2781Mapper {

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

@Mapping(target = "nested", source = "source")
Target map(Source source);

class Target {
private Source nested;

public Source getNested() {
return nested;
}

public void setNested(Source nested) {
this.nested = nested;
}
}

class Source {
private String field1;
private String field2;

public Source(String field1, String field2) {
this.field1 = field1;
this.field2 = field2;
}

public String getField1() {
return field1;
}

public String getField2() {
return field2;
}
}
}
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.ap.test.bugs._2781;

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

/**
* @author Mengxing Yuan
*/
@IssueKey("2781")
@WithClasses({
Issue2781Mapper.class
})
class Issue2781Test {

@ProcessorTest
void shouldCompileWithoutErrors() {
}
}