Closed cvetan closed 1 year ago
Can you provide a simple example (minimal reproduciable at best)?
Do you mean mapping composition as seen here in the reference documentation?
I'll send you example from my code. Just to get to my computer.
same applies to mappers who inherit configuration from another mapper e.g.
import org.mapstruct.InheritConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Mapper
public interface Demo {
@Mapping(source = "fieldOne", target = "field1")
@Mapping(source = "fieldTwo", target = "field2")
TargetObject1 sourceToTarget1(SourceObject address);
@InheritConfiguration(name = "sourceToTarget1")
@Mapping(source = "fieldThree", target = "field3")
TargetObject2 sourceToTarget2(SourceObject address);
@Data
class SourceObject {
private String fieldOne;
private String fieldTwo;
private String fieldThree;
}
@Data
class TargetObject1 {
protected String field1;
protected String field2;
}
@EqualsAndHashCode(callSuper = true)
@Data
class TargetObject2 extends TargetObject1 {
private String field3;
}
}
Generated code
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2023-02-06T14:55:49+0100",
comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.6 (Eclipse Adoptium)"
)
public class DemoImpl implements Demo {
@Override
public TargetObject1 sourceToTarget1(SourceObject address) {
if ( address == null ) {
return null;
}
TargetObject1 targetObject1 = new TargetObject1();
targetObject1.setField1( address.getFieldOne() );
targetObject1.setField2( address.getFieldTwo() );
return targetObject1;
}
@Override
public TargetObject2 sourceToTarget2(SourceObject address) {
if ( address == null ) {
return null;
}
TargetObject2 targetObject2 = new TargetObject2();
targetObject2.setField3( address.getFieldThree() );
targetObject2.setField1( address.getFieldOne() );
targetObject2.setField2( address.getFieldTwo() );
return targetObject2;
}
}
Intellij: Build #IU-223.8617.56, built on January 26, 2023 MapStruct Plugin: 1.4.0
Closing this as a duplicate of #65
In one mapper class we have multiple same mappings used in couple of mapping methods. For this we made custom annotations which contain these mappings. Plugin doesn't recognize those attributes and shows warning for "unmapped" fields, even tough fields are mapped and code built successfully.