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

258
Vistas
Spring/Spring Boot conversion - how to make a chain on Converters?

Please look at the example below:

class Foo
class Bar
class Baz

@Component
class FooToBarConverter : Converter<Foo, Bar> {
    override fun convert(source: Foo) = Bar()
}

@Component
class BarToBazConverter : Converter<Bar, Baz> {
    override fun convert(source: Bar) = Baz()
}

@RestController("/test")
class TestController(val conversionService: ConversionService) {
    @GetMapping
    fun get() = "test: " + conversionService.convert(Foo(), Baz::class.java)
    // must convert Foo to Bar, then Bar to Baz, but throws an exception instead
}

Is there any way to achieve the desired behavior without reinventing the wheel?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You Can use
@Autowired private List<Converter> allConverter;

This will inject all beans that are implementing the Converter interface.

Now you can loop throw the list and class convert method.

allConverter.stream().forEach(Converter::convert);

To Manage the order of converters, you need to sort list.

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