Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

356
Views
Mapper is not using another mapper, how to use a mapper from another mapper?

I am experimenting with MapStruct where I want to have a mapper use another mapper to combine multiple objects into one. For my tests I have three domain objects, DomainObject1, DomainObject2 and DomainObject3. I want to convert DomainObject1 to a DTO, TransferObjectA, which has a field containing a second DTO, TransferObjectB, that is constructed using DomainObject2 and DomainObject3.

I have two mappers, one that converts DomainObject2 and DomainObject3 to TransferObjectB which ignores a field in DomainObject2 so it isn't converted:

@Mapper
public interface ObjectBMapper {

  @Mapping(target = "field1", ignore = true)
  TransferObjectB domainObject2ToTransferObjectB(DomainObject2 domainObject2, DomainObject3 domainObject3);
}

And a second mapper that converts DomainObject1 to TransferObjectA which also accepts DomainObject2 and DomainObject3 so they can be converted using the above mapper and put on the resulting TransferObjectA:

@Mapper(uses = ObjectBMapper.class)
public interface ObjectAMapper {

  TransferObjectA domainObject1ToTransferObjectA(DomainObject1 domainObject1, DomainObject2 domainObject2, DomainObject3 domainObject3);
}

However, the ObjectBMapper doesn't seem to be used by the ObjectAMapper and the field1 is converted (this results in an error because it is an enum). Why is the ObjectBMapper not used and how can I make sure that is will be used by ObjectAMapper?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

MapStruct currently can only use other mappers with a single source parameter. There is an open feature request mapstruct/mapstruct#2081 about this functionality.

What you could do is to use a wrapper object instead of multiple source parameters.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!