Skip to content

Unexpected code generated for update method icw nested target properties #1011

@sjaakd

Description

@sjaakd

The following mapper

@Mapper
public interface WellMapper {

    @Mapping( target = "deliveredVerticalPosition.groundLevelPosition.value", source = "wellData.groundLevelPosition")
    @Mapping( target = "deliveredVerticalPosition.groundLevelPositioningMethod", source = "wellData.groundLevelPositioningMethod")
    void merge( @MappingTarget MonitoringWell target, EventData source );
}

Generates the following code:

 public class WellMapperImpl implements WellMapper {

    @Override
    public void merge(MonitoringWell target, EventData source) {
        if ( source == null ) {
            return;
        }

        DeliveredVerticalPosition deliveredVerticalPosition = new DeliveredVerticalPosition();
        VerticalPosition groundLevelPosition = new VerticalPosition();
        deliveredVerticalPosition.setGroundLevelPosition( groundLevelPosition );
        target.setDeliveredVerticalPosition( deliveredVerticalPosition );

        deliveredVerticalPosition.setGroundLevelPositioningMethod( sourceWellDataGroundLevelPositioningMethod( source ) );
        groundLevelPosition.setValue( sourceWellDataGroundLevelPosition( source ) );
    }

    private String sourceWellDataGroundLevelPositioningMethod(EventData eventData) {

        if ( eventData == null ) {
            return null;
        }
        WellData wellData = eventData.getWellData();
        if ( wellData == null ) {
            return null;
        }
        String groundLevelPositioningMethod = wellData.getGroundLevelPositioningMethod();
        if ( groundLevelPositioningMethod == null ) {
            return null;
        }
        return groundLevelPositioningMethod;
    }

    private BigDecimal sourceWellDataGroundLevelPosition(EventData eventData) {

        if ( eventData == null ) {
            return null;
        }
        WellData wellData = eventData.getWellData();
        if ( wellData == null ) {
            return null;
        }
        BigDecimal groundLevelPosition = wellData.getGroundLevelPosition();
        if ( groundLevelPosition == null ) {
            return null;
        }
        return groundLevelPosition;
    }
}

Note that new objects are generated, while I would expect that the nested objects would be obtained from the @MappingTarget

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions