我正在使用CsvDozerBeanWriter
将 bean 实例写入 CSV 文件。遵循我在将 bean 写入 CSV 之前使用的示例代码。CsvDozerBeanWriter#configureBeanMapping(...)
除非 bean 的String
属性为空(而不是null
),否则一切正常。我发现这样的属性CsvDozerBeanData
在写之前并没有从bean复制到中间实例。这会导致异常,因为列数与单元处理器的数量不匹配。
深入研究我发现这configureBeanMapping(...)
相当于将推土机的设置map-empty-string
为False
. 因此,所有空字符串都没有被映射(null
字符串仍然被映射)。
我该如何克服呢?提供我自己的DozerBeanMapper
(如文档所述)是最好的方法吗?
更新:
以下是我得到的异常的详细信息:
org.supercsv.exception.SuperCsvException: The number of columns to be processed (7) must match the number of CellProcessors (12): check that the number of CellProcessors you have defined matches the expected number of columns being read/written
context={lineNo=2, rowNo=2, columnNo=1, rowSource=[a, b, c, d, e, f, g]}
org.supercsv.exception.SuperCsvException: The number of columns to be processed (7) must match the number of CellProcessors (12): check that the number of CellProcessors you have defined matches the expected number of columns being read/written
context={lineNo=2, rowNo=2, columnNo=1, rowSource=[a, b, c, d, e, f, g]}
at org.supercsv.util.Util.executeCellProcessors(Util.java:78)
at org.supercsv.io.dozer.CsvDozerBeanWriter.write(CsvDozerBeanWriter.java:133)
beanString
具有a
通过l
. h
通过的属性l
是空字符串。
更新 2:
这是一个测试用例。