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

CsvDataFormat should be completed with 'CSVFormat.withTrim'

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.18.1
    • Fix Version/s: 2.18.3, 2.19.0
    • Component/s: camel-csv
    • Labels:
      None
    • Estimated Complexity:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: