Menu

#30 Using CSVBeanWriter to write empty Columns

2.0.0-beta-1
closed
None
5
2012-09-16
2012-03-08
Anonymous
No

Hi,

With CSVBeanReader the processiong of a column may omitted using "null" as headerColumn.
Doing the same thing with CSVBeanWriter leads to a NPE.

The Error occures at Line 67 of Version 1.6.0-SNAPSHOT.

I fixed it in my copy using following code instead of the lines 67 and 68:
if(methodName == null) {
result.add(null);
} else {
Method getMethod = cache.getGetMethod(source, methodName);
result.add(getMethod.invoke(source));
}

Using this and a ConverNullTo Processor enables writing empty/omitted columns.

Discussion

  • James Bassett

    James Bassett - 2012-03-09

    Hi Ed,

    I'll look into this, but my initial feeling is that it doesn't really make sense to use null as a header column. If you don't want to write the column, then why not remove it altogether from the nameMapping array? I don't believe you could actually write the header with writeHeader() if you have a null column name anyway.

    James

     
  • Anonymous

    Anonymous - 2012-03-09

    Hi James,

    in my case there is a defined column list, which must be supplied. So I have to add a column, which has no representation in my bean. Just like in the reader-case, where I can omit a column from the file and the bean doesn't have to have a dummy property.

    I did the following:
    - writeHeader with a String[] containing all header columns filled
    - write with a String[], where the "omitted-to-be" columns were replaced with null

    null within the writeHeader would lead to an NPE I guess.

    regards
    ed

     
  • James Bassett

    James Bassett - 2012-07-29

    I've updated CsvBeanWriter to allow for null entries in the nameMapping array ( see revision 231). This will result in an empty column (""). Also, note that I've updated all writers to write null as "" (previously you had to use a ConvertNullTo("") which was annoying).

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.