Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: [Spring Boot] Spring type conversion API bridge

...

Code Block
languagejava
@Component
public class InvoiceProcessor {

  @Autowired
  private TypeConverter typeConverter;

  public long parseInvoiceValue(Invoice invoice) {
    String invoiceValue = invoice.grossValue();
    return typeConverter.convertTo(Long.class, invoiceValue);
  }

}

Spring type conversion API bridge

Spring comes with the powerful type conversion API. Spring API happens not to be much different from the Camel type converter API. As those APIs are so similar, Camel Spring Boot automatically registers bridge converter (SpringTypeConverter) that delegates to the Spring conversion API. It basically means that out-of-the-box Camel will threat Spring Converters as Camel ones. With this approach you can enjoy both Camel and Spring converters accessed via Camel TypeConverter API:

Code Block
languagejava
@Component
public class InvoiceProcessor {

  @Autowired
  private TypeConverter typeConverter;

  public UUID parseInvoiceId(Invoice invoice) {
    // Using Spring's StringToUUIDConverter
    UUID id = invoice.typeConverter.convertTo(UUID.class, invoice.getId());
  }

}


Include Page
Endpoint See Also
Endpoint See Also