javaspring-bootdependency-injectionapache-camelbindy

Camel bindy separator configurable through properties


I use Apache Camel in a Spring Boot Java project. I have to parse a csv and split the lines with a separator. I use camel bindy to parse the csv and read it as a pojo bean class.

Here is how I configure the camel bindy

@CsvRecord( separator = "," )
public Class MyClass {
}

Here is my question: how can I change the separator value dynamically, reading it from a property? I've tried @CsvRecord( separator = "${my-prop.separator}" ) but it did not work.


Solution

  • Not that I know of. If you have a known set of delimiters, you could have a separate DTO class (w/ @CsvRecord annotation) for each one, i.e. MyClassComma, MyClassSemicolon, etc. Then at runtime choose the correct DTO class based on a spring property that specifies the delimiter.