Menu

#178 CsvBindAndJoinByName not working with Regex

v1.0 (example)
closed-works-for-me
None
5
2018-09-21
2018-08-09
Anwar Saleh
No

I made a csv

row,bloomberg,anwar_12,anwar_more_12
1,Anwar,Saleh,noway

public class TestModel {

@CsvBindByName(column = "row")
int row;

@CsvBindByName(column = "name")
String name;

@CsvBindAndJoinByName(column = "^anwar_\\d{2}$", elementType = String.class)
MultiValuedMap<String, String> anwar;

@CsvBindAndJoinByName(column = "^anwar_more_\\d{2}$", elementType = String.class)
MultiValuedMap<String, String> anwarMore;

//setters and getters

}

and its not working

Related

Bugs: #178

Discussion

  • Anwar Saleh

    Anwar Saleh - 2018-08-09

    adjusting the bloomberg should be name

    row,name,anwar_12,anwar_more_12
    1,Anwar,Saleh,noway

     

    Last edit: Anwar Saleh 2018-08-09
  • Andrew Rucker Jones

    • assigned_to: Andrew Rucker Jones
     
    • Anwar Saleh

      Anwar Saleh - 2018-08-09

      So the mulitvaluedmap doesnt not contain the column and value, that matches
      the regex.

      They always contain null

      On Thu, 9 Aug 2018 at 20:13, Andrew Rucker Jones aruckerjones@users.sourceforge.net wrote:

      • assigned_to: Andrew Rucker Jones
      • Comment:

      Could you specify what you mean by "it's not working"? I just ran a test
      with exactly the information you sent and everything works fine for me.


      Status: open
      Group: v1.0 (example)
      Created: Thu Aug 09, 2018 05:02 PM UTC by Anwar Saleh
      Last Updated: Thu Aug 09, 2018 05:03 PM UTC
      Owner: Andrew Rucker Jones

      I made a csv

      row,bloomberg,anwar_12,anwar_more_12
      1,Anwar,Saleh,noway

      public class TestModel {

      @CsvBindByName(column = "row")
      int row;

      @CsvBindByName(column = "name")
      String name;

      @CsvBindAndJoinByName(column = "^anwar_\d{2}$", elementType = String.class)
      MultiValuedMap<string, string=""> anwar;</string,>

      @CsvBindAndJoinByName(column = "^anwar_more_\d{2}$", elementType = String.class)
      MultiValuedMap<string, string=""> anwarMore;</string,>

      //setters and getters

      }

      and its not working

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/opencsv/bugs/178/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #178

  • Andrew Rucker Jones

    Could you specify what you mean by "it's not working"? I just ran a test with exactly the information you sent and everything works fine for me.

     
  • Andrew Rucker Jones

    Could you please attach a test case that demonstrates this? I can't reproduce the problem.

     
  • Anwar Saleh

    Anwar Saleh - 2018-08-10

    I done few adjustments to make it simpler

    Reading in file method.

    @Test
        public void csv_Test() throws IOException {
            Reader reader;
            CsvToBean<TestModel> csvReader;
            Iterator<TestModel> iterator;
            reader = new InputStreamReader(new FileInputStream(new File("E:\\testing_folder\\Testing.csv")), "Cp1252");
    
            csvReader = new CsvToBeanBuilder<TestModel>(reader).withType(TestModel.class).build();
            iterator = csvReader.iterator();
    
            while (iterator.hasNext()) {
                TestModel bean = iterator.next();
                LOG.info(bean.getName());
            }
    
            reader.close();
        }
    

    Model used

    public class TestModel {
    
    @CsvBindByName(column = "row")
    int row;
    
    @CsvBindByName(column = "name")
    String name;
    
    @CsvBindAndJoinByName(column = "^email_\\d{1}$", elementType = String.class)
    MultiValuedMap<String, String> email;
    
    public int getRow() {
        return row;
    }
    
    public void setRow(int row) {
        this.row = row;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public MultiValuedMap<String, String> getEmail() {
        return email;
    }
    
    public void setEmail(MultiValuedMap<String, String> email) {
        this.email = email;
    }
    
    }
    
    the CSV
    
    row,name,email_1,email_2
    1,Anwar,a@u.com,s@u.com
    2,Othman,o@u.com,a@u.com
    
    screenshot of emails being null attached
    
     
  • Andrew Rucker Jones

    Ah. I haven't had the time yet to test your newest attachment (I'm in the middle of another development), but I have a suspicion: Don't use the Iterator. It should work, of course, and I'll fix it, but I suspect that's the problem.

     
    • Anwar Saleh

      Anwar Saleh - 2018-08-10

      I done the following

      @Test
      public void csv_Test() throws IOException {
      Reader reader;
      reader = new InputStreamReader(new FileInputStream(new
      File("E:\testing_folder\Testing.csv")), "Cp1252");

      List<testmodel> listOfModel = new
      CsvToBeanBuilder<testmodel>(reader).withType(TestModel.class).build().parse();</testmodel></testmodel>

      reader.close();
      }

      The result is the same.

      I appreciate the work you are doing, but would you know when your able to
      get round to this?

      Thank you in advance.

      On Fri, Aug 10, 2018 at 2:04 PM, Andrew Rucker Jones aruckerjones@users.sourceforge.net wrote:

      Ah. I haven't had the time yet to test your newest attachment (I'm in the
      middle of another development), but I have a suspicion: Don't use the
      Iterator. It should work, of course, and I'll fix it, but I suspect that's
      the problem.


      Status: open
      Group: v1.0 (example)
      Created: Thu Aug 09, 2018 05:02 PM UTC by Anwar Saleh
      Last Updated: Fri Aug 10, 2018 09:12 AM UTC
      Owner: Andrew Rucker Jones

      I made a csv

      row,bloomberg,anwar_12,anwar_more_12
      1,Anwar,Saleh,noway

      public class TestModel {

      @CsvBindByName(column = "row")
      int row;

      @CsvBindByName(column = "name")
      String name;

      @CsvBindAndJoinByName(column = "^anwar_\d{2}$", elementType = String.class)
      MultiValuedMap<string, string=""> anwar;</string,>

      @CsvBindAndJoinByName(column = "^anwar_more_\d{2}$", elementType = String.class)
      MultiValuedMap<string, string=""> anwarMore;</string,>

      //setters and getters

      }

      and its not working

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/opencsv/bugs/178/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #178

      • Andrew Rucker Jones

        Honest estimate? I think I'm aiming for a release in September, which would include a fix for this bug, if I can reproduce it.

         
  • Andrew Rucker Jones

    Once again, I copied your (new) code and your data and I cannot reproduce your problem. Can you please verify with a hex editor that your input file only includes the characters you expect it to include? Sometimes there is an invisible BOM at the beginning of the file. I could also imagine files encoded in a wide character set, which opencsv would not be able to parse properly unless the file is read in with the proper encoding.

     
  • Andrew Rucker Jones

    • status: open --> closed-works-for-me
     
  • Andrew Rucker Jones

    Lacking a response and a way to reproduce this, I'm closing the ticket.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.