0

I'm using SuperCSV to parse a CSV file. The problem i'm having is I have 3 other classes - Office, Vehicle and Car.

I've made OFfice The Grasp Creator so it creates objects of type Vehicle, and Vehicle exntends Car.

The class called ImportCSV implements SuperCSV library. ImportCSV needs access to all the methods in OFfice, Vehicle and Car to parse the CSV file otherwise i'm getting the error - SuperCsvReflectionException.

How can I give access to the Class ImportCSV to all the methods of 3 different classes, or any suggestions on how to go about this please?

Harry
  • 467
  • 1
  • 5
  • 14
  • Can you post the stacktrace of that exception? And some sample code. It's awfully hard to understand the problem otherwise. – James Bassett Jun 24 '14 at 06:16
  • this is the output: `Exception in thread "main" org.supercsv.exception.SuperCsvReflectionException: unable to find method setTYCODE(java.lang.String) in class portal.Office - check that the corresponding nameMapping element matches the field name in the bean, and the cell processor returns a type compatible with the field` The method i'm trying to run is : `while( (tenantRecord = beanReader.read(Office.class, header, processors)) != null )` tenantRecord is of type Office – Harry Jun 24 '14 at 17:32

1 Answers1

0

Based on the stacktrace, I'm guessing the field mapping you've supplied is incorrect.

As of Super CSV 2.2.0, the case is ignored when trying to find a matching getter/setter. So you can supply a nameMapping of "TYCODE" and it will match setTycode(), setTYCODE(), etc.

In versions prior to that, the case must match (it uppercased the first char and prepended 'set' to get the name of the setter). In this case the setter would have to be called setTYCODE().

My guess is that you're using an older version of Super CSV, and that your header and the field name are in different cases. i.e. the header has "TYCODE" but the field name in your Office class is tycode. That or the setter isn't public.

James Bassett
  • 9,458
  • 4
  • 35
  • 68
  • Thanks for your help but that didn't work. The setters are all public and all method cases are correct. The problem is that all methods need to be in one single class, and as it stands it isn't. The setters in 3 separate classes hence the problem. The only solution I can think of is to include all setters inside one class although for my application I separated it into different classes for a reason. – Harry Jun 26 '14 at 00:47
  • Sorry I may have misunderstood. Are you using the [Dozer extension](http://supercsv.sourceforge.net/dozer.html)? It can access all the setters in nested classes (and instantiate the classes for you), while the standard CsvBeanReader can't. – James Bassett Jun 26 '14 at 03:28
  • No i'm using the the standard CsvBeanReader. So the Dozer extension should make it compile without errors? – Harry Jun 26 '14 at 10:13
  • No, it's slightly different. Take a look at the examples on the website and see if it will help. Without any sample CSV/code I'm still unsure what you're trying to do. – James Bassett Jun 26 '14 at 11:05