42BV / CSVeed

Light-weight, easy-to-use Java-based CSV utility
Apache License 2.0
100 stars 22 forks source link

BeanProperties.java should not be using getDeclaredFields() #63

Open aner-perez opened 9 years ago

aner-perez commented 9 years ago

BeanProperties.java uses getDeclaredFields() to iterate over properties in a bean but not all properties on a bean need to have a corresponding field on the class. This causes unwarranted CsvExceptions to be thrown claiming "Property does not exist".

A bean can have many properties which have no corresponding field on the class.

For example:

class A {
    String[] values = new String[2];
    public void setName(String name) {
        values[0] = name;
    }
    public void getName() {
        return values[0];
    }
    public void setLogin(String login) {
        values[1] = login;
    }
    public void getLogin() {
        return values[1];
    }
}

This class would have 1 field called "values" but 2 properties called "name" and "login"

Record classes generated by JOOQ are a real-world example of this pattern.