-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullPointerException with Bean writing with custom mapped column names #46
Comments
Better formatted version of above: I'm getting a NullPointerException in the constructor of HeaderImpl.
I suspect the issue is that the loop for
is iterating through every property picked up by introspection, and ignoring the fact that properties may have been manually mapped. For reading purposes, I generate I create my BeanInstructions (formerly BeanReaderInstructions) as follows:
TolerantColumnNameMapper is a ColumnNameMapper that tolaterates missing column names when reading. If I have an old zip file and I've added a field to a Bean, it just gives a warning when the zip file is missing something as opposed to throwing an exception and terminating out of the entire reading process:
|
I understand the use case, although I have been unable to reproduce the error. Would you be able to provide a compact unit test that traps the error? |
I'm getting a NullPointerException in the constructor of HeaderImpl.
public HeaderImpl(Line row) {
this.header = row;
Column currentColumn = new Column();
for (String headerCell : header) {
this.indexToName.put(currentColumn, headerCell);
this.nameToIndex.put(headerCell.toLowerCase(), currentColumn);
currentColumn = currentColumn.nextColumn();
}
}
I suspect the issue is that the loop for
(String headerCell : header) {
is iterating through every property picked up by introspection, and ignoring the fact that properties may have been manually mapped. For reading purposes, I generate I create my BeanInstructions (formerly BeanReaderInstructions) as follows:
private static BeanInstructions getListedPropertiesBeanInstructions(Class clazz,
Collection pids) {
BeanInstructions bi = new BeanInstructionsImpl(clazz);
bi.setMapper(TolerantColumnNameMapper.class);
for (String pid : pids) {
try {
bi.mapColumnNameToProperty(pid, pid);
} catch (CsvException ce) {
ce.printStackTrace();
}
}
return bi;
}
TolerantColumnNameMapper is a ColumnNameMapper that tolaterates missing column names when reading. If I have an old zip file and I've added a field to a Bean, it just gives a warning when the zip file is missing something as opposed to throwing an exception and terminating out of the entire reading process:
import org.csveed.api.Header;
import org.csveed.bean.ColumnNameMapper;
import org.csveed.common.Column;
import org.csveed.report.CsvException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TolerantColumnNameMapper extends ColumnNameMapper {
private final static Logger LOGGER = LoggerFactory.getLogger(TolerantColumnNameMapper.class);
}
The text was updated successfully, but these errors were encountered: