Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support overloading for target #1135

Open
quantumlexa opened this issue Mar 12, 2017 · 5 comments
Open

Support overloading for target #1135

quantumlexa opened this issue Mar 12, 2017 · 5 comments
Assignees
Milestone

Comments

@quantumlexa
Copy link

Mapstruct does support overloading of target setters(see: Issue892Test test) but choosing preferred type logic is based on getter type of target - not source, which looks a bit strange.
org.mapstruct.ap.internal.model.common.Type#getPropertyWriteAccessors: line 465

Please see unit test:
Source:

public class Source {

    private Date updatedOn;

    public Source(Date updatedOn) {
        this.updatedOn = updatedOn;
    }

    public Date getUpdatedOn() {
        return updatedOn;
    }

    public void setUpdatedOn(Date updatedOn) {
        this.updatedOn = updatedOn;
    }
}

Target:

public class Target {

    private long updatedOn;

    public long getUpdatedOn() {
        return updatedOn;
    }

    public void setUpdatedOn( long updatedOn ) {
        this.updatedOn = updatedOn;
    }

    public void setUpdatedOn( Date updatedOn ) {
        if (updatedOn == null) {
            return;
        }
        this.updatedOn = updatedOn.getTime();
    }

}

Mapper:

@Mapper
public interface SourceTargetMapper {

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

    @Mapping(target = "updatedOn", source = "updatedOn")
    Target sourceToTarget( Source source );

}

UnitTest:

@WithClasses({
        SourceTargetMapper.class,
        Source.class,
        Target.class
})
@RunWith(AnnotationProcessorTestRunner.class)
public class OverloadingTest {

    @Test
    public void testShouldGenerateCorrectMapperImplementation() {
        Source source = new Source( new Date() );
        Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
        Assert.assertTrue( target.getUpdatedOn() > 0 );
    }

}
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Mar 12, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Mar 14, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Mar 16, 2017
@filiphr filiphr added this to the 1.2.0.CR1 milestone Mar 18, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Mar 27, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Mar 31, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Mar 31, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Mar 31, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Mar 31, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Mar 31, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Mar 31, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Apr 1, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Apr 1, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Apr 1, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Apr 1, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Apr 1, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Apr 1, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Apr 4, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Apr 21, 2017
@filiphr filiphr modified the milestones: 1.2.0.CR1, 1.2.0.Beta3 May 17, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Jun 1, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Jun 1, 2017
quantumlexa pushed a commit to quantumlexa/mapstruct that referenced this issue Jun 1, 2017
@gunnarmorling gunnarmorling modified the milestones: 1.3.x, 1.2.0.CR1 Jun 27, 2017
@filiphr filiphr modified the milestones: 1.3.0.Beta1, 1.3.x Apr 6, 2018
@filiphr filiphr modified the milestones: 1.3.0.Beta2, 2.0 Oct 11, 2018
@pduartee
Copy link

+1

1 similar comment
@rivierej
Copy link

+1

@aioobe
Copy link

aioobe commented Dec 18, 2022

This was never merged? Is there a particular reason?

@filiphr
Copy link
Member

filiphr commented Feb 5, 2023

The PR for this hasn't been merged since the MapStruct team hasn't had the time to look into it in detail. The PR is not a small change (functionality wise). Therefore, we need to be careful when merging it.

@onurcelik98
Copy link

Is there an estimation about when this may be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants