1

I am using Super-CSV to write a CSV file but I am having problems when I want to access a property in a class that is also a property of the original class.

I'll try to explain myself better:

I have let's say class Car, which has a property Model which has a property name, and in the csv file, where I am writing the properties of Car, I want to write the Model name.

I have written the following:

ICsvBeanWriter beanWriter = null;

try {

     beanWriter = new CsvBeanWriter(new FileWriter(file), CsvPreference.EXCEL_PREFERENCE);

     String[] header = {"Plate Number", "Model"};
     String[] properties = {"plateNumber", "model.name"};

     CellProcessor[] processors = new CellProcessor[] {
          new NotNull(); // plateNumber
          new NotNull(); // model.name
     };

     beanWriter.writeHeader(header);

     List<Car> cars = getCarList();

     for (Car car: cars) {
          beanWriter.write(car, properties, processors);
     }
} catch(IOException ioe) {
// ...
}

But when I run it, it complaints about "model.name"... How should I do it? I have found a workaround and is to write a "getModelName()" method in Car class and define the property as "modelName" , but I don't like it...

diminuta
  • 1,545
  • 8
  • 32
  • 55

0 Answers0