Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-10853

CsvDataFormat should be completed with 'CSVFormat.withTrim'

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.18.1
    • 2.18.3, 2.19.0
    • camel-csv
    • None
    • Unknown

    Description

      In Camel org.apache.commons.csv.CSVFormat is indirectly configured via org.apache.camel.model.dataformat.CsvDataFormat. Although it is possible to tell CSVFormat to trim leading and trailing blanks via CSVFormat.withTrim, this property can NOT be set in CsvDataFormat.

      Workaround

      As a workaround, one could do the following:

      CsvDataFormat dataFormat = new CsvDataFormat("\t") {
      
                  @Override
                  protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
                      // This is how we force the engine to trim the values
                      org.apache.camel.dataformat.csv.CsvDataFormat csvDataFormat = (org.apache.camel.dataformat.csv.CsvDataFormat) dataFormat;
                      CSVFormat format = csvDataFormat.getFormat();
                      csvDataFormat.setFormat(format.withTrim());
                      super.configureDataFormat(csvDataFormat, camelContext);
                  }
              };
      

      Question

      Are they other properties which should be considered?

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            christianr Christian Ribeaud
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: