Uploaded image for project: 'Red Hat Fuse'
  1. Red Hat Fuse
  2. ENTESB-22628

camel-bindy does not unmarshall as expected when csv column has String like "a,b"

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • fuse-7.13-GA
    • fuse-7.12-GA
    • Camel
    • None
    • Very Likely

      +underlined text+If csv data has a column like "a,b",  camel-bindy's unmarshall does not work as expected.
      Please check the attached reproducer.

      sample csv.data

      SH-01L,"Android,10,0",3,4,5,6,7,8,9,100,0,0,0,0,0,0,0,0,0,0,1,0,0,0"
      

      RdModelSupportAppCsvModel class has 8 fields.

      @CsvRecord(separator = ",", autospanLine = true, quote = "\"", skipFirstLine = true)
      public class RdModelSupportAppCsvModel {
      
          @DataField(pos = 1)
          private String uaName;
      
          @DataField(pos = 2)
          private String uaOs;
      
          @DataField(pos = 3)
          private String uaChar;
      
          @DataField(pos = 4)
          private String resultName;
      
          @DataField(pos = 5)
          private String resultHosting;
      
          @DataField(pos = 6)
          private String iosFlg;
      
          @DataField(pos = 7)
          private String nativeFlg;
      
          @DataField(pos = 8)
          @BindyConverter(AppIdentificationConvrtter.class)
          private List<String> appIdentificationList;
      

      camel-bindy does unmarshall the data like this.

      13:39:06.793 [Camel (MyCamel) thread #1 - file://data] INFO  csv-route - Post Body: SH-01LAndroid,10,03456,7,8,9,100,0,0,0,0,0,0,0,0,0,0,1,0,0,0
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - uaName : "SH-01L"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - uaOs : "Android,10,0"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - uaChar : "3"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - resultName : "4"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - resultHosting : "5"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - iosFlg : "6,7,8,9,100,0,0,0,0,0,0,0,0,0,0,1,0,0,0"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - nativeFlg : ""
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - appIdentificationList:
      

      The expected result is like this.

      13:39:06.793 [Camel (MyCamel) thread #1 - file://data] INFO  csv-route - Post Body: SH-01LAndroid,10,03456,7,8,9,100,0,0,0,0,0,0,0,0,0,0,1,0,0,0
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - uaName : "SH-01L"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - uaOs : "Android,10,0"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - uaChar : "3"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - resultName : "4"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - resultHosting : "5"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - iosFlg : "6"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - nativeFlg : "7"
      13:39:06.794 [Camel (MyCamel) thread #1 - file://data] INFO  com.sample.processor.ResultProcessor - appIdentificationList: "8,9,100,0,0,0,0,0,0,0,0,0,0,1,0,0,0"
      

      It looks like org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat internally invokes java.util.regex.Pattern.split() and the result was not the expected one.

      String[] tokens = pattern.split(trimmedLine, factory.getAutospanLine() ? factory.getMaxpos() : -1); //Line 234
      

      Debugger shows the return value of pattern.split() as follows:
      split() returned String[8] (id=138)

      [0]	"SH-01L" (id=170)	
      [1]	""Android" (id=171)	
      [2]	"10" (id=172)	
      [3]	"0"" (id=173)	
      [4]	"3" (id=174)	
      [5]	"4" (id=175)	
      [6]	"5" (id=176)	
      [7]	"6,7,8,9,100,0,0,0,0,0,0,0,0,0,0,1,0,0,0" (id=177)	
      

      Unfortunately, pattern.split() does not have any option to treat the data pattern like "a,b", so I guess camel-bindy needs to use another Class to split the csv data as expected.

            fmariani@redhat.com Federico Mariani
            rhn-support-hfuruich Hisao Furuichi
            Federico Mariani Federico Mariani
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: