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

Intellij plugin reports unmapped properties which are mapped in custom annotation #118

Closed
cvetan opened this issue Dec 7, 2022 · 5 comments

Comments

@cvetan
Copy link

cvetan commented Dec 7, 2022

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.

@thunderhook
Copy link
Contributor

Can you provide a simple example (minimal reproduciable at best)?

@thunderhook
Copy link
Contributor

Do you mean mapping composition as seen here in the reference documentation?

@cvetan
Copy link
Author

cvetan commented Dec 27, 2022

I'll send you example from my code. Just to get to my computer.

@Chr3is
Copy link

Chr3is commented Feb 6, 2023

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;
    }
}

Bildschirm­foto 2023-02-06 um 15 02 43

Intellij: Build #IU-223.8617.56, built on January 26, 2023
MapStruct Plugin: 1.4.0

@filiphr
Copy link
Member

filiphr commented Apr 2, 2023

Closing this as a duplicate of #65

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

4 participants