mercredi 18 avril 2018

Netbeans Platform - Reflection Problems Across Modules?

I have a Maven based Netbeans Platform application. In this application I have developed and added two Maven based modules:

  1. The first module simply contains a POJO with some Gson and OpenCSV annotations.
  2. The 2nd module contains the necessary logic to parse CSV files using OpenCSV into objects based on the POJO of the 1st module.

Basically what Module 2 does is the following:

public List<Book> buildBooksFromCSV() throws FileNotFoundException {
        List<Book> books;

        CsvToBean ctb = new CsvToBeanBuilder(new FileReader(csvFile))
                .withType(Book.class)
                .withOrderedResults(true)
                .withFieldAsNull(CSVReaderNullFieldIndicator.BOTH)
                .build();

        books = ctb.parse();

        return books;
    }

When executing the logic of module 2 I experience the following:

  1. OpenCSV cannot parse the CSV file and generate beans with correct property values if there are not getters or setters. This results in null values for the properties of the bean
  2. OpenCSV cannot parse List fields using a the space-separated converter. This results in an exception trying to parse the column with the space separated list of values.

This is strange because if I move the POJO into the 2nd module and discard the 1st module. Everything works like a charm:

  • OpenCSV can generate the beans even if the POJO has no getters or setters.
  • OpenCSV can parse and assign List fields to the bean

When parsing CSV into beans, OpenCSV concurrency and reflection.

I have a feeling that this is some reflection issue between OpenCSV and Netbeans Platform. Yet I cannot really understand why this only occurs when things are separated into different modules. Any insight would be greatly appreciated.





Aucun commentaire:

Enregistrer un commentaire