2

I have following DTO and Domain objects. I am using Mapstruct to copy domain object to DTO object.

public class AddressDomain {
            private String street;
            private Telephone telephone;
    }
public class CompanyDomain{
        private String id;
        private Address address;
}

public class AddressDTO {
            private String street;
            private Telephone telephone;
    }
public class CompanyDTO{
        private String id;
        private Address address;
}

Mapping Domain to DTO using below Mapper. i don't want to map telephone property from domain to DTO. How to do that? i tried providing nested target property in mapping ignore but it gives error:

public interface CompanyMapper {
    //**below line gives error**
    @Mapping(target = "address.telephone", ignore=true)
    CompanyDTO map(AddressDTO dto);
}

1 Answer 1

7

Your current definition maps an address into a company object which doesn't seem right. You need to declare two methods, one for mapping addresses and one for mapping companies (whose generated implementation will in turn invoke the address mapping method):

public interface CompanyMapper {

    CompanyDTO map(Company company);

    @Mapping(target="telephone", ignore=true)
    AddressDTO map(Address address);
}
Sign up to request clarification or add additional context in comments.

1 Comment

can you look my question please? stackoverflow.com/questions/45652298/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.