Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

359
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda