Giter Site home page Giter Site logo

Comments (5)

thunderhook avatar thunderhook commented on June 20, 2024

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

from mapstruct-idea.

thunderhook avatar thunderhook commented on June 20, 2024

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

from mapstruct-idea.

cvetan avatar cvetan commented on June 20, 2024

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

from mapstruct-idea.

Chr3is avatar Chr3is commented on June 20, 2024

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

from mapstruct-idea.

filiphr avatar filiphr commented on June 20, 2024

Closing this as a duplicate of #65

from mapstruct-idea.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.