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

Record with "is" prefixed Boolean field causes unmapped source property report #2596

Closed
KENNYSOFT opened this issue Sep 29, 2021 · 2 comments · Fixed by #2612
Closed

Record with "is" prefixed Boolean field causes unmapped source property report #2596

KENNYSOFT opened this issue Sep 29, 2021 · 2 comments · Fixed by #2612
Labels
Milestone

Comments

@KENNYSOFT
Copy link

KENNYSOFT commented Sep 29, 2021

Given files:

MemberDto.java

package org.mapstruct.itest.records;

public record MemberDto(Boolean isActive, Boolean premium) {

}

MemberEntity.java

package org.mapstruct.itest.records;

public class MemberEntity {

    private Boolean isActive;
    private Boolean premium;

    public Boolean getIsActive() {
        return isActive;
    }

    public void setIsActive(Boolean isActive) {
...

MemberMapper.java

package org.mapstruct.itest.records;

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

@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR)
public interface MemberMapper {

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

    MemberEntity fromRecord(MemberDto record);

    MemberDto toRecord(MemberEntity entity);

}

And following method added to org.mapstruct.itest.records.RecordsTest:

import org.mapstruct.itest.records.MemberDto;
import org.mapstruct.itest.records.MemberEntity;
import org.mapstruct.itest.records.MemberMapper;

...

    @Test
    public void shouldMapMemberRecord() {
        MemberEntity member = MemberMapper.INSTANCE.fromRecord( new MemberDto( true, false ) );

        assertThat( member ).isNotNull();
        assertThat( member.getIsActive() ).isTrue();
        assertThat( member.getPremium() ).isFalse();
    }

    @Test
    public void shouldMapIntoMemberRecord() {
        MemberEntity entity = new MemberEntity();
        entity.setIsActive( false );
        entity.setPremium( true );

        MemberDto value = MemberMapper.INSTANCE.toRecord( entity );

        assertThat( value ).isNotNull();
        assertThat( value.isActive() ).isEqualTo( false );
        assertThat( value.premium() ).isEqualTo( true );
    }

Test failed with compilation error:

[ERROR] /.../mapstruct/integrationtest/target/tmp/org.mapstruct.itest.tests.recordsTest/javac/src/main/java/org/mapstruct/itest/records/MemberMapper.java:[22,18] Unmapped source property: "active".

If I remove unmappedSourcePolicy from @Mapping, it just passes well.

(But actually I cannot find any warning when I removed unmappedSourcePolicy, maybe the maven test task just remove warnings?)

Environment

MapStruct 1.5.0-SNAPSHOT (as of 8b84f5b)

Java

openjdk version "17" 2021-09-14 LTS
OpenJDK Runtime Environment Zulu17.28+13-CA (build 17+35-LTS)
OpenJDK 64-Bit Server VM Zulu17.28+13-CA (build 17+35-LTS, mixed mode, sharing)

filiphr added a commit to filiphr/mapstruct that referenced this issue Oct 16, 2021
@filiphr
Copy link
Member

filiphr commented Oct 16, 2021

Thanks for the detailed example. It really helped us find the problem and prepare a fix in PR #2612

The reason why it works when you remove unmappedSourcePolicy is because the default value for that is ignore, so it is ignore. If you set it to ReportPolicy.WARNING you'll see a warning.

@KENNYSOFT
Copy link
Author

Cool. Thanks for preparing the fix and really looking forward to the merge.

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

Successfully merging a pull request may close this issue.

2 participants