Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

357
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda